BigW Consortium Gitlab
Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
G
gitlab-ce
Project
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
Forest Godfrey
gitlab-ce
Commits
021d53c9
Commit
021d53c9
authored
Mar 14, 2016
by
Jacob Vosmaer
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Run 'git gc' every 10 pushes
parent
a02fe251
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
65 additions
and
5 deletions
+65
-5
git_push_service.rb
app/services/git_push_service.rb
+8
-0
housekeeping_service.rb
app/services/projects/housekeeping_service.rb
+14
-2
20160314143402_projects_add_pushes_since_gc.rb
db/migrate/20160314143402_projects_add_pushes_since_gc.rb
+5
-0
schema.rb
db/schema.rb
+2
-1
git_push_service_spec.rb
spec/services/git_push_service_spec.rb
+27
-0
housekeeping_service_spec.rb
spec/services/projects/housekeeping_service_spec.rb
+9
-2
No files found.
app/services/git_push_service.rb
View file @
021d53c9
...
...
@@ -49,6 +49,8 @@ class GitPushService < BaseService
# Update merge requests that may be affected by this push. A new branch
# could cause the last commit of a merge request to change.
update_merge_requests
perform_housekeeping
end
def
update_main_language
...
...
@@ -73,6 +75,12 @@ class GitPushService < BaseService
ProjectCacheWorker
.
perform_async
(
@project
.
id
)
end
def
perform_housekeeping
housekeeping
=
Projects
::
HousekeepingService
.
new
(
@project
)
housekeeping
.
increment!
housekeeping
.
execute
if
housekeeping
.
needed?
end
def
process_default_branch
@push_commits
=
project
.
repository
.
commits
(
params
[
:newrev
])
...
...
app/services/projects/housekeeping_service.rb
View file @
021d53c9
...
...
@@ -19,9 +19,21 @@ module Projects
if
!
try_obtain_lease
return
"Housekeeping was already triggered in the past
#{
LEASE_TIMEOUT
/
60
}
minutes"
end
GitlabShellWorker
.
perform_async
(
:gc
,
@project
.
path_with_namespace
)
return
"Housekeeping successfully started"
@project
.
pushes_since_gc
=
0
@project
.
save!
"Housekeeping successfully started"
end
def
needed?
@project
.
pushes_since_gc
>=
10
end
def
increment!
@project
.
pushes_since_gc
+=
1
@project
.
save!
end
private
...
...
db/migrate/20160314143402_projects_add_pushes_since_gc.rb
0 → 100644
View file @
021d53c9
class
ProjectsAddPushesSinceGc
<
ActiveRecord
::
Migration
def
change
add_column
:projects
,
:pushes_since_gc
,
:integer
,
default:
0
end
end
db/schema.rb
View file @
021d53c9
...
...
@@ -11,7 +11,7 @@
#
# It's strongly recommended that you check this file into your version control system.
ActiveRecord
::
Schema
.
define
(
version:
201603
09140734
)
do
ActiveRecord
::
Schema
.
define
(
version:
201603
14143402
)
do
# These are extensions that must be enabled in order to support this database
enable_extension
"plpgsql"
...
...
@@ -711,6 +711,7 @@ ActiveRecord::Schema.define(version: 20160309140734) do
t
.
boolean
"pending_delete"
,
default:
false
t
.
boolean
"public_builds"
,
default:
true
,
null:
false
t
.
string
"main_language"
t
.
integer
"pushes_since_gc"
,
default:
0
end
add_index
"projects"
,
[
"builds_enabled"
,
"shared_runners_enabled"
],
name:
"index_projects_on_builds_enabled_and_shared_runners_enabled"
,
using: :btree
...
...
spec/services/git_push_service_spec.rb
View file @
021d53c9
...
...
@@ -401,6 +401,33 @@ describe GitPushService, services: true do
end
end
describe
"housekeeping"
do
let
(
:housekeeping
)
{
instance_double
(
'Projects::HousekeepingService'
,
increment!:
nil
,
needed?:
false
)
}
before
do
allow
(
Projects
::
HousekeepingService
).
to
receive
(
:new
).
and_return
(
housekeeping
)
end
it
'does not perform housekeeping when not needed'
do
expect
(
housekeeping
).
not_to
receive
(
:execute
)
execute_service
(
project
,
user
,
@oldrev
,
@newrev
,
@ref
)
end
it
'performs housekeeping when needed'
do
expect
(
housekeeping
).
to
receive
(
:needed?
).
and_return
(
true
)
expect
(
housekeeping
).
to
receive
(
:execute
)
execute_service
(
project
,
user
,
@oldrev
,
@newrev
,
@ref
)
end
it
'increments the push counter'
do
expect
(
housekeeping
).
to
receive
(
:increment!
)
execute_service
(
project
,
user
,
@oldrev
,
@newrev
,
@ref
)
end
end
def
execute_service
(
project
,
user
,
oldrev
,
newrev
,
ref
)
service
=
described_class
.
new
(
project
,
user
,
oldrev:
oldrev
,
newrev:
newrev
,
ref:
ref
)
service
.
execute
...
...
spec/services/projects/housekeeping_service_spec.rb
View file @
021d53c9
...
...
@@ -37,4 +37,12 @@ describe Projects::HousekeepingService do
expect
(
subject
.
needed?
).
to
eq
(
true
)
end
end
end
\ No newline at end of file
describe
:increment!
do
it
'increments the pushes_since_gc counter'
do
expect
(
project
.
pushes_since_gc
).
to
eq
(
0
)
subject
.
increment!
expect
(
project
.
pushes_since_gc
).
to
eq
(
1
)
end
end
end
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment