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
2a66b81f
Commit
2a66b81f
authored
Aug 13, 2019
by
GitLab Bot
Browse files
Options
Browse Files
Download
Plain Diff
Automatic merge of gitlab-org/gitlab-ce master
parents
5091d431
1c3b570c
Changes
8
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
105 additions
and
12 deletions
+105
-12
app/models/repository.rb
app/models/repository.rb
+9
-5
app/workers/post_receive.rb
app/workers/post_receive.rb
+2
-0
changelogs/unreleased/sh-only-flush-tags-once-per-push.yml
changelogs/unreleased/sh-only-flush-tags-once-per-push.yml
+5
-0
lib/gitlab/git_post_receive.rb
lib/gitlab/git_post_receive.rb
+6
-0
spec/lib/gitlab/git_post_receive_spec.rb
spec/lib/gitlab/git_post_receive_spec.rb
+43
-0
spec/models/repository_spec.rb
spec/models/repository_spec.rb
+12
-1
spec/services/git/tag_push_service_spec.rb
spec/services/git/tag_push_service_spec.rb
+2
-2
spec/workers/post_receive_spec.rb
spec/workers/post_receive_spec.rb
+26
-4
No files found.
app/models/repository.rb
View file @
2a66b81f
...
...
@@ -418,25 +418,29 @@ class Repository
end
# Runs code before pushing (= creating or removing) a tag.
#
# Note that this doesn't expire the tags. You may need to call
# expire_caches_for_tags or expire_tags_cache.
def
before_push_tag
repository_event
(
:push_tag
)
end
def
expire_caches_for_tags
expire_statistics_caches
expire_emptiness_caches
expire_tags_cache
repository_event
(
:push_tag
)
end
# Runs code before removing a tag.
def
before_remove_tag
expire_tags_cache
expire_statistics_caches
expire_caches_for_tags
repository_event
(
:remove_tag
)
end
# Runs code after removing a tag.
def
after_remove_tag
expire_
tags_cache
expire_
caches_for_tags
end
# Runs code after the HEAD of a repository is changed.
...
...
app/workers/post_receive.rb
View file @
2a66b81f
...
...
@@ -44,6 +44,8 @@ class PostReceive
# Expire the branches cache so we have updated data for this push
post_received
.
project
.
repository
.
expire_branches_cache
if
post_received
.
includes_branches?
# We only need to expire tags once per push
post_received
.
project
.
repository
.
expire_caches_for_tags
if
post_received
.
includes_tags?
post_received
.
enum_for
(
:changes_refs
).
with_index
do
|
(
oldrev
,
newrev
,
ref
),
index
|
service_klass
=
...
...
changelogs/unreleased/sh-only-flush-tags-once-per-push.yml
0 → 100644
View file @
2a66b81f
---
title
:
Only expire tag cache once per push
merge_request
:
31641
author
:
type
:
performance
lib/gitlab/git_post_receive.rb
View file @
2a66b81f
...
...
@@ -33,6 +33,12 @@ module Gitlab
end
end
def
includes_tags?
enum_for
(
:changes_refs
).
any?
do
|
_oldrev
,
_newrev
,
ref
|
Gitlab
::
Git
.
tag_ref?
(
ref
)
end
end
private
def
deserialize_changes
(
changes
)
...
...
spec/lib/gitlab/git_post_receive_spec.rb
View file @
2a66b81f
...
...
@@ -49,4 +49,47 @@ describe ::Gitlab::GitPostReceive do
end
end
end
describe
'#includes_tags?'
do
context
'with no tags'
do
let
(
:changes
)
do
<<~
EOF
654321 210987 refs/notags/tag1
654322 210986 refs/heads/test1
654323 210985 refs/merge-requests/mr1
EOF
end
it
'returns false'
do
expect
(
subject
.
includes_tags?
).
to
be_falsey
end
end
context
'with tags'
do
let
(
:changes
)
do
<<~
EOF
654322 210986 refs/heads/test1
654321 210987 refs/tags/tag1
654323 210985 refs/merge-requests/mr1
EOF
end
it
'returns true'
do
expect
(
subject
.
includes_tags?
).
to
be_truthy
end
end
context
'with malformed changes'
do
let
(
:changes
)
do
<<~
EOF
ref/tags/1 a
sometag refs/tags/2
EOF
end
it
'returns false'
do
expect
(
subject
.
includes_tags?
).
to
be_falsey
end
end
end
end
spec/models/repository_spec.rb
View file @
2a66b81f
...
...
@@ -1744,12 +1744,23 @@ describe Repository do
end
end
describe
'#
before_push_tag
'
do
describe
'#
expires_caches_for_tags
'
do
it
'flushes the cache'
do
expect
(
repository
).
to
receive
(
:expire_statistics_caches
)
expect
(
repository
).
to
receive
(
:expire_emptiness_caches
)
expect
(
repository
).
to
receive
(
:expire_tags_cache
)
repository
.
expire_caches_for_tags
end
end
describe
'#before_push_tag'
do
it
'logs an event'
do
expect
(
repository
).
not_to
receive
(
:expire_statistics_caches
)
expect
(
repository
).
not_to
receive
(
:expire_emptiness_caches
)
expect
(
repository
).
not_to
receive
(
:expire_tags_cache
)
expect
(
repository
).
to
receive
(
:repository_event
).
with
(
:push_tag
)
repository
.
before_push_tag
end
end
...
...
spec/services/git/tag_push_service_spec.rb
View file @
2a66b81f
...
...
@@ -26,8 +26,8 @@ describe Git::TagPushService do
subject
end
it
'
flushes
the tags cache'
do
expect
(
project
.
repository
).
to
receive
(
:expire_tags_cache
)
it
'
does not flush
the tags cache'
do
expect
(
project
.
repository
).
not_
to
receive
(
:expire_tags_cache
)
subject
end
...
...
spec/workers/post_receive_spec.rb
View file @
2a66b81f
...
...
@@ -85,8 +85,20 @@ describe PostReceive do
end
end
context
'tags'
do
let
(
:changes
)
{
'123456 789012 refs/tags/tag'
}
context
"tags"
do
let
(
:changes
)
do
<<~
EOF
654321 210987 refs/tags/tag1
654322 210986 refs/tags/tag2
654323 210985 refs/tags/tag3
654324 210984 refs/tags/tag4
654325 210983 refs/tags/tag5
EOF
end
before
do
expect
(
Gitlab
::
GlRepository
).
to
receive
(
:parse
).
and_return
([
project
,
Gitlab
::
GlRepository
::
PROJECT
])
end
it
'does not expire branches cache'
do
expect
(
project
.
repository
).
not_to
receive
(
:expire_branches_cache
)
...
...
@@ -94,8 +106,18 @@ describe PostReceive do
described_class
.
new
.
perform
(
gl_repository
,
key_id
,
base64_changes
)
end
it
'calls Git::TagPushService'
do
expect_next_instance_of
(
Git
::
TagPushService
)
do
|
service
|
it
"only invalidates tags once"
do
expect
(
project
.
repository
).
to
receive
(
:repository_event
).
exactly
(
5
).
times
.
with
(
:push_tag
).
and_call_original
expect
(
project
.
repository
).
to
receive
(
:expire_caches_for_tags
).
once
.
and_call_original
expect
(
project
.
repository
).
to
receive
(
:expire_tags_cache
).
once
.
and_call_original
described_class
.
new
.
perform
(
gl_repository
,
key_id
,
base64_changes
)
end
it
"calls Git::TagPushService"
do
expect
(
Git
::
BranchPushService
).
not_to
receive
(
:new
)
expect_any_instance_of
(
Git
::
TagPushService
)
do
|
service
|
expect
(
service
).
to
receive
(
:execute
).
and_return
(
true
)
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