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
Boxiang Sun
gitlab-ce
Commits
536f74ff
Commit
536f74ff
authored
May 23, 2017
by
Kamil Trzciński
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'zj-fix-pipeline-etag' into 'master'
Fix pipeline etag Closes #32658 See merge request !11615
parents
d07e85e1
b518cd86
Changes
9
Show whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
104 additions
and
1 deletion
+104
-1
app/models/commit_status.rb
app/models/commit_status.rb
+1
-0
app/workers/expire_job_cache_worker.rb
app/workers/expire_job_cache_worker.rb
+35
-0
app/workers/expire_pipeline_cache_worker.rb
app/workers/expire_pipeline_cache_worker.rb
+9
-0
changelogs/unreleased/zj-fix-pipeline-etag.yml
changelogs/unreleased/zj-fix-pipeline-etag.yml
+4
-0
lib/gitlab/etag_caching/router.rb
lib/gitlab/etag_caching/router.rb
+1
-1
spec/lib/gitlab/etag_caching/router_spec.rb
spec/lib/gitlab/etag_caching/router_spec.rb
+11
-0
spec/models/commit_status_spec.rb
spec/models/commit_status_spec.rb
+10
-0
spec/workers/expire_job_cache_worker_spec.rb
spec/workers/expire_job_cache_worker_spec.rb
+31
-0
spec/workers/expire_pipeline_cache_worker_spec.rb
spec/workers/expire_pipeline_cache_worker_spec.rb
+2
-0
No files found.
app/models/commit_status.rb
View file @
536f74ff
...
@@ -89,6 +89,7 @@ class CommitStatus < ActiveRecord::Base
...
@@ -89,6 +89,7 @@ class CommitStatus < ActiveRecord::Base
else
else
PipelineUpdateWorker
.
perform_async
(
pipeline
.
id
)
PipelineUpdateWorker
.
perform_async
(
pipeline
.
id
)
end
end
ExpireJobCacheWorker
.
perform_async
(
commit_status
.
id
)
end
end
end
end
end
end
...
...
app/workers/expire_job_cache_worker.rb
0 → 100644
View file @
536f74ff
class
ExpireJobCacheWorker
include
Sidekiq
::
Worker
include
BuildQueue
def
perform
(
job_id
)
job
=
CommitStatus
.
joins
(
:pipeline
,
:project
).
find_by
(
id:
job_id
)
return
unless
job
pipeline
=
job
.
pipeline
project
=
job
.
project
Gitlab
::
EtagCaching
::
Store
.
new
.
tap
do
|
store
|
store
.
touch
(
project_pipeline_path
(
project
,
pipeline
))
store
.
touch
(
project_job_path
(
project
,
job
))
end
end
private
def
project_pipeline_path
(
project
,
pipeline
)
Gitlab
::
Routing
.
url_helpers
.
namespace_project_pipeline_path
(
project
.
namespace
,
project
,
pipeline
,
format: :json
)
end
def
project_job_path
(
project
,
job
)
Gitlab
::
Routing
.
url_helpers
.
namespace_project_build_path
(
project
.
namespace
,
project
,
job
.
id
,
format: :json
)
end
end
app/workers/expire_pipeline_cache_worker.rb
View file @
536f74ff
...
@@ -10,6 +10,7 @@ class ExpirePipelineCacheWorker
...
@@ -10,6 +10,7 @@ class ExpirePipelineCacheWorker
store
=
Gitlab
::
EtagCaching
::
Store
.
new
store
=
Gitlab
::
EtagCaching
::
Store
.
new
store
.
touch
(
project_pipelines_path
(
project
))
store
.
touch
(
project_pipelines_path
(
project
))
store
.
touch
(
project_pipeline_path
(
project
,
pipeline
))
store
.
touch
(
commit_pipelines_path
(
project
,
pipeline
.
commit
))
if
pipeline
.
commit
store
.
touch
(
commit_pipelines_path
(
project
,
pipeline
.
commit
))
if
pipeline
.
commit
store
.
touch
(
new_merge_request_pipelines_path
(
project
))
store
.
touch
(
new_merge_request_pipelines_path
(
project
))
each_pipelines_merge_request_path
(
project
,
pipeline
)
do
|
path
|
each_pipelines_merge_request_path
(
project
,
pipeline
)
do
|
path
|
...
@@ -28,6 +29,14 @@ class ExpirePipelineCacheWorker
...
@@ -28,6 +29,14 @@ class ExpirePipelineCacheWorker
format: :json
)
format: :json
)
end
end
def
project_pipeline_path
(
project
,
pipeline
)
Gitlab
::
Routing
.
url_helpers
.
namespace_project_pipeline_path
(
project
.
namespace
,
project
,
pipeline
,
format: :json
)
end
def
commit_pipelines_path
(
project
,
commit
)
def
commit_pipelines_path
(
project
,
commit
)
Gitlab
::
Routing
.
url_helpers
.
pipelines_namespace_project_commit_path
(
Gitlab
::
Routing
.
url_helpers
.
pipelines_namespace_project_commit_path
(
project
.
namespace
,
project
.
namespace
,
...
...
changelogs/unreleased/zj-fix-pipeline-etag.yml
0 → 100644
View file @
536f74ff
---
title
:
Fix issue where real time pipelines were not cached
merge_request
:
11615
author
:
lib/gitlab/etag_caching/router.rb
View file @
536f74ff
...
@@ -38,7 +38,7 @@ module Gitlab
...
@@ -38,7 +38,7 @@ module Gitlab
'project_pipelines'
'project_pipelines'
),
),
Gitlab
::
EtagCaching
::
Router
::
Route
.
new
(
Gitlab
::
EtagCaching
::
Router
::
Route
.
new
(
%r(^(?!.*(
#{
RESERVED_WORDS
}
)).*/pipelines/
\d
+
\.
json
\z
)
,
%r(^(?!.*(
#{
RESERVED_WORDS
_REGEX
}
)).*/pipelines/
\d
+
\.
json
\z
)
,
'project_pipeline'
'project_pipeline'
)
)
].
freeze
].
freeze
...
...
spec/lib/gitlab/etag_caching/router_spec.rb
View file @
536f74ff
...
@@ -77,6 +77,17 @@ describe Gitlab::EtagCaching::Router do
...
@@ -77,6 +77,17 @@ describe Gitlab::EtagCaching::Router do
expect
(
result
).
to
be_blank
expect
(
result
).
to
be_blank
end
end
it
'matches pipeline#show endpoint'
do
env
=
build_env
(
'/my-group/my-project/pipelines/2.json'
)
result
=
described_class
.
match
(
env
)
expect
(
result
).
to
be_present
expect
(
result
.
name
).
to
eq
'project_pipeline'
end
def
build_env
(
path
)
def
build_env
(
path
)
{
'PATH_INFO'
=>
path
}
{
'PATH_INFO'
=>
path
}
end
end
...
...
spec/models/commit_status_spec.rb
View file @
536f74ff
...
@@ -36,6 +36,16 @@ describe CommitStatus, :models do
...
@@ -36,6 +36,16 @@ describe CommitStatus, :models do
it
{
is_expected
.
to
eq
(
commit_status
.
user
)
}
it
{
is_expected
.
to
eq
(
commit_status
.
user
)
}
end
end
describe
'status state machine'
do
let!
(
:commit_status
)
{
create
(
:commit_status
,
:running
,
project:
project
)
}
it
'invalidates the cache after a transition'
do
expect
(
ExpireJobCacheWorker
).
to
receive
(
:perform_async
).
with
(
commit_status
.
id
)
commit_status
.
success!
end
end
describe
'#started?'
do
describe
'#started?'
do
subject
{
commit_status
.
started?
}
subject
{
commit_status
.
started?
}
...
...
spec/workers/expire_job_cache_worker_spec.rb
0 → 100644
View file @
536f74ff
require
'spec_helper'
describe
ExpireJobCacheWorker
do
set
(
:pipeline
)
{
create
(
:ci_empty_pipeline
)
}
let
(
:project
)
{
pipeline
.
project
}
subject
{
described_class
.
new
}
describe
'#perform'
do
context
'with a job in the pipeline'
do
let
(
:job
)
{
create
(
:ci_build
,
pipeline:
pipeline
)
}
it
'invalidates Etag caching for the job path'
do
pipeline_path
=
"/
#{
project
.
full_path
}
/pipelines/
#{
pipeline
.
id
}
.json"
job_path
=
"/
#{
project
.
full_path
}
/builds/
#{
job
.
id
}
.json"
expect_any_instance_of
(
Gitlab
::
EtagCaching
::
Store
).
to
receive
(
:touch
).
with
(
pipeline_path
)
expect_any_instance_of
(
Gitlab
::
EtagCaching
::
Store
).
to
receive
(
:touch
).
with
(
job_path
)
subject
.
perform
(
job
.
id
)
end
end
context
'when there is no job in the pipeline'
do
it
'does not change the etag store'
do
expect
(
Gitlab
::
EtagCaching
::
Store
).
not_to
receive
(
:new
)
subject
.
perform
(
9999
)
end
end
end
end
spec/workers/expire_pipeline_cache_worker_spec.rb
View file @
536f74ff
...
@@ -10,9 +10,11 @@ describe ExpirePipelineCacheWorker do
...
@@ -10,9 +10,11 @@ describe ExpirePipelineCacheWorker do
it
'invalidates Etag caching for project pipelines path'
do
it
'invalidates Etag caching for project pipelines path'
do
pipelines_path
=
"/
#{
project
.
full_path
}
/pipelines.json"
pipelines_path
=
"/
#{
project
.
full_path
}
/pipelines.json"
new_mr_pipelines_path
=
"/
#{
project
.
full_path
}
/merge_requests/new.json"
new_mr_pipelines_path
=
"/
#{
project
.
full_path
}
/merge_requests/new.json"
pipeline_path
=
"/
#{
project
.
full_path
}
/pipelines/
#{
pipeline
.
id
}
.json"
expect_any_instance_of
(
Gitlab
::
EtagCaching
::
Store
).
to
receive
(
:touch
).
with
(
pipelines_path
)
expect_any_instance_of
(
Gitlab
::
EtagCaching
::
Store
).
to
receive
(
:touch
).
with
(
pipelines_path
)
expect_any_instance_of
(
Gitlab
::
EtagCaching
::
Store
).
to
receive
(
:touch
).
with
(
new_mr_pipelines_path
)
expect_any_instance_of
(
Gitlab
::
EtagCaching
::
Store
).
to
receive
(
:touch
).
with
(
new_mr_pipelines_path
)
expect_any_instance_of
(
Gitlab
::
EtagCaching
::
Store
).
to
receive
(
:touch
).
with
(
pipeline_path
)
subject
.
perform
(
pipeline
.
id
)
subject
.
perform
(
pipeline
.
id
)
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