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
1
Merge Requests
1
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
nexedi
gitlab-ce
Commits
0047429a
Commit
0047429a
authored
Nov 23, 2018
by
Heinrich Lee Yu
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Cache project HEAD to prevent unnecessary Gitaly calls
parent
aed88cd4
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
9 additions
and
26 deletions
+9
-26
lib/gitlab/cache/ci/project_pipeline_status.rb
lib/gitlab/cache/ci/project_pipeline_status.rb
+9
-26
No files found.
lib/gitlab/cache/ci/project_pipeline_status.rb
View file @
0047429a
...
...
@@ -9,8 +9,6 @@ module Gitlab
class
ProjectPipelineStatus
attr_accessor
:sha
,
:status
,
:ref
,
:project
,
:loaded
delegate
:commit
,
to: :project
def
self
.
load_for_project
(
project
)
new
(
project
).
tap
do
|
status
|
status
.
load_status
...
...
@@ -18,33 +16,12 @@ module Gitlab
end
def
self
.
load_in_batch_for_projects
(
projects
)
cached_results_for_projects
(
projects
).
zip
(
projects
).
each
do
|
result
,
project
|
project
.
pipeline_status
=
new
(
project
,
result
)
projects
.
each
do
|
project
|
project
.
pipeline_status
=
new
(
project
)
project
.
pipeline_status
.
load_status
end
end
def
self
.
cached_results_for_projects
(
projects
)
result
=
Gitlab
::
Redis
::
Cache
.
with
do
|
redis
|
redis
.
multi
do
projects
.
each
do
|
project
|
cache_key
=
cache_key_for_project
(
project
)
redis
.
exists
(
cache_key
)
redis
.
hmget
(
cache_key
,
:sha
,
:status
,
:ref
)
end
end
end
result
.
each_slice
(
2
).
map
do
|
(
cache_key_exists
,
(
sha
,
status
,
ref
))
|
pipeline_info
=
{
sha:
sha
,
status:
status
,
ref:
ref
}
{
loaded_from_cache:
cache_key_exists
,
pipeline_info:
pipeline_info
}
end
end
def
self
.
cache_key_for_project
(
project
)
"
#{
Gitlab
::
Redis
::
Cache
::
CACHE_NAMESPACE
}
:project:
#{
project
.
id
}
:pipeline_status:
#{
project
.
commit
&
.
sha
}
"
end
def
self
.
update_for_pipeline
(
pipeline
)
pipeline_info
=
{
sha:
pipeline
.
sha
,
...
...
@@ -132,7 +109,13 @@ module Gitlab
end
def
cache_key
self
.
class
.
cache_key_for_project
(
project
)
"
#{
Gitlab
::
Redis
::
Cache
::
CACHE_NAMESPACE
}
:project:
#{
project
.
id
}
:pipeline_status:
#{
commit
&
.
sha
}
"
end
def
commit
return
@commit
if
defined?
(
@commit
)
@commit
=
project
.
commit
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