From e658f9603c99ca6a8ef4c0292b2cdab2916fb09e Mon Sep 17 00:00:00 2001 From: Stan Hu Date: Tue, 13 Aug 2019 09:04:30 -0700 Subject: Only expire tag cache once per push Previously each tag in a push would invoke the Gitaly `FindAllTags` RPC since the tag cache would be invalidated with every tag. We can eliminate those extraneous calls by expiring the tag cache once in `PostReceive` and taking advantage of the cached tags. Relates to https://gitlab.com/gitlab-org/gitlab-ce/issues/65795 --- app/models/repository.rb | 14 +++++++++----- app/workers/post_receive.rb | 2 ++ 2 files changed, 11 insertions(+), 5 deletions(-) (limited to 'app') diff --git a/app/models/repository.rb b/app/models/repository.rb index 58abfaef801..9d45a12fa6e 100644 --- a/app/models/repository.rb +++ b/app/models/repository.rb @@ -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. diff --git a/app/workers/post_receive.rb b/app/workers/post_receive.rb index d8dfbc0faf7..675fa1a73ca 100644 --- a/app/workers/post_receive.rb +++ b/app/workers/post_receive.rb @@ -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 = -- cgit v1.2.1