Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Léo-Paul Géneau
gitlab-ce
Commits
366f617e
Commit
366f617e
authored
Feb 09, 2016
by
Yorick Peterse
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'caching-repository-git-operations' into 'master'
See merge request !2752
parents
7383453b
9a99d8e4
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
140 additions
and
6 deletions
+140
-6
CHANGELOG
CHANGELOG
+1
-0
app/models/project.rb
app/models/project.rb
+2
-0
app/models/repository.rb
app/models/repository.rb
+19
-3
app/services/git_push_service.rb
app/services/git_push_service.rb
+4
-0
spec/models/repository_spec.rb
spec/models/repository_spec.rb
+84
-3
spec/services/git_push_service_spec.rb
spec/services/git_push_service_spec.rb
+30
-0
No files found.
CHANGELOG
View file @
366f617e
Please view this file on the master branch, on stable branches it's out of date.
v 8.5.0 (unreleased)
- Cache various Repository methods to improve performance (Yorick Peterse)
- Ensure rake tasks that don't need a DB connection can be run without one
- Update New Relic gem to 3.14.1.311 (Stan Hu)
- Add "visibility" flag to GET /projects api endpoint
...
...
app/models/project.rb
View file @
366f617e
...
...
@@ -790,6 +790,8 @@ class Project < ActiveRecord::Base
def
change_head
(
branch
)
# Cached divergent commit counts are based on repository head
repository
.
expire_branch_cache
repository
.
expire_root_ref_cache
gitlab_shell
.
update_repository_head
(
self
.
path_with_namespace
,
branch
)
reload_default_branch
end
...
...
app/models/repository.rb
View file @
366f617e
...
...
@@ -44,7 +44,9 @@ class Repository
end
def
empty?
raw_repository
.
empty?
return
@empty
unless
@empty
.
nil?
@empty
=
cache
.
fetch
(
:empty?
)
{
raw_repository
.
empty?
}
end
#
...
...
@@ -57,7 +59,11 @@ class Repository
# This method return true if repository contains some content visible in project page.
#
def
has_visible_content?
raw_repository
.
branch_count
>
0
return
@has_visible_content
unless
@has_visible_content
.
nil?
@has_visible_content
=
cache
.
fetch
(
:has_visible_content?
)
do
raw_repository
.
branch_count
>
0
end
end
def
commit
(
id
=
'HEAD'
)
...
...
@@ -243,6 +249,16 @@ class Repository
end
end
def
expire_root_ref_cache
cache
.
expire
(
:root_ref
)
@root_ref
=
nil
end
def
expire_has_visible_content_cache
cache
.
expire
(
:has_visible_content?
)
@has_visible_content
=
nil
end
def
rebuild_cache
cache_keys
.
each
do
|
key
|
cache
.
expire
(
key
)
...
...
@@ -480,7 +496,7 @@ class Repository
end
def
root_ref
@root_ref
||=
raw_repository
.
root_ref
@root_ref
||=
cache
.
fetch
(
:root_ref
)
{
raw_repository
.
root_ref
}
end
def
commit_dir
(
user
,
path
,
message
,
branch
)
...
...
app/services/git_push_service.rb
View file @
366f617e
...
...
@@ -21,8 +21,12 @@ class GitPushService
project
.
repository
.
expire_cache
if
push_remove_branch?
(
ref
,
newrev
)
project
.
repository
.
expire_has_visible_content_cache
@push_commits
=
[]
elsif
push_to_new_branch?
(
ref
,
oldrev
)
project
.
repository
.
expire_has_visible_content_cache
# Re-find the pushed commits.
if
is_default_branch?
(
ref
)
# Initial push to the default branch. Take the full history of that branch as "newly pushed".
...
...
spec/models/repository_spec.rb
View file @
366f617e
...
...
@@ -232,11 +232,92 @@ describe Repository, models: true do
end
describe
'when there are branches'
do
before
do
allow
(
repository
.
raw_repository
).
to
receive
(
:branch_count
).
and_return
(
3
)
it
'returns true'
do
expect
(
repository
.
raw_repository
).
to
receive
(
:branch_count
).
and_return
(
3
)
expect
(
subject
).
to
eq
(
true
)
end
it
'caches the output'
do
expect
(
repository
.
raw_repository
).
to
receive
(
:branch_count
).
once
.
and_return
(
3
)
repository
.
has_visible_content?
repository
.
has_visible_content?
end
end
end
describe
'#empty?'
do
let
(
:empty_repository
)
{
create
(
:project_empty_repo
).
repository
}
it
'returns true for an empty repository'
do
expect
(
empty_repository
.
empty?
).
to
eq
(
true
)
end
it
'returns false for a non-empty repository'
do
expect
(
repository
.
empty?
).
to
eq
(
false
)
end
it
'caches the output'
do
expect
(
repository
.
raw_repository
).
to
receive
(
:empty?
).
once
.
and_return
(
false
)
repository
.
empty?
repository
.
empty?
end
end
describe
'#root_ref'
do
it
'returns a branch name'
do
expect
(
repository
.
root_ref
).
to
be_an_instance_of
(
String
)
end
it
'caches the output'
do
expect
(
repository
.
raw_repository
).
to
receive
(
:root_ref
).
once
.
and_return
(
'master'
)
repository
.
root_ref
repository
.
root_ref
end
end
describe
'#expire_cache'
do
it
'expires all caches'
do
expect
(
repository
).
to
receive
(
:expire_branch_cache
)
repository
.
expire_cache
end
end
describe
'#expire_root_ref_cache'
do
it
'expires the root reference cache'
do
repository
.
root_ref
expect
(
repository
.
raw_repository
).
to
receive
(
:root_ref
).
once
.
and_return
(
'foo'
)
repository
.
expire_root_ref_cache
expect
(
repository
.
root_ref
).
to
eq
(
'foo'
)
end
end
describe
'#expire_has_visible_content_cache'
do
it
'expires the visible content cache'
do
repository
.
has_visible_content?
expect
(
repository
.
raw_repository
).
to
receive
(
:branch_count
).
once
.
and_return
(
0
)
repository
.
expire_has_visible_content_cache
it
{
is_expected
.
to
eq
(
true
)
}
expect
(
repository
.
has_visible_content?
).
to
eq
(
false
)
end
end
end
spec/services/git_push_service_spec.rb
View file @
366f617e
...
...
@@ -21,6 +21,18 @@ describe GitPushService, services: true do
end
it
{
is_expected
.
to
be_truthy
}
it
'flushes general cached data'
do
expect
(
project
.
repository
).
to
receive
(
:expire_cache
)
subject
end
it
'flushes the visible content cache'
do
expect
(
project
.
repository
).
to
receive
(
:expire_has_visible_content_cache
)
subject
end
end
context
'existing branch'
do
...
...
@@ -29,6 +41,12 @@ describe GitPushService, services: true do
end
it
{
is_expected
.
to
be_truthy
}
it
'flushes general cached data'
do
expect
(
project
.
repository
).
to
receive
(
:expire_cache
)
subject
end
end
context
'rm branch'
do
...
...
@@ -37,6 +55,18 @@ describe GitPushService, services: true do
end
it
{
is_expected
.
to
be_truthy
}
it
'flushes the visible content cache'
do
expect
(
project
.
repository
).
to
receive
(
:expire_has_visible_content_cache
)
subject
end
it
'flushes general cached data'
do
expect
(
project
.
repository
).
to
receive
(
:expire_cache
)
subject
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