diff options
author | Yorick Peterse <yorickpeterse@gmail.com> | 2016-11-18 14:04:18 +0100 |
---|---|---|
committer | Yorick Peterse <yorickpeterse@gmail.com> | 2016-11-21 15:05:13 +0100 |
commit | ffb9b3ef18dee6f7e561ff53253da42a25854c6c (patch) | |
tree | d91a5bf12070281871e1628d7e757cd9b09006f1 /app/services | |
parent | 6f393877e555c9e87017747cd70d3577bb70a03e (diff) | |
download | gitlab-ce-ffb9b3ef18dee6f7e561ff53253da42a25854c6c.tar.gz |
Refactor cache refreshing/expiring
This refactors repository caching so it's possible to selectively
refresh certain caches, instead of just expiring and refreshing
everything.
To allow this the various methods that were cached (e.g. "tag_count" and
"readme") use a similar pattern that makes expiring and refreshing
their data much easier.
In this new setup caches are refreshed as follows:
1. After a commit (but before running ProjectCacheWorker) we expire some
basic caches such as the commit count and repository size.
2. ProjectCacheWorker will recalculate the commit count, repository
size, then refresh a specific set of caches based on the list of
files changed in a push payload.
This requires a bunch of changes to the various methods that may be
cached. For one, data should not be cached if a branch used or the
entire repository does not exist. To prevent all these methods from
handling this manually this is taken care of in
Repository#cache_method_output. Some methods still manually check for
the existence of a repository but this result is also cached.
With selective flushing implemented ProjectCacheWorker no longer uses an
exclusive lease for all of its work. Instead this worker only uses a
lease to limit the number of times the repository size is updated as
this is a fairly expensive operation.
Diffstat (limited to 'app/services')
-rw-r--r-- | app/services/git_push_service.rb | 23 |
1 files changed, 21 insertions, 2 deletions
diff --git a/app/services/git_push_service.rb b/app/services/git_push_service.rb index 77c6c81cc1b..647930d555c 100644 --- a/app/services/git_push_service.rb +++ b/app/services/git_push_service.rb @@ -18,7 +18,7 @@ class GitPushService < BaseService # def execute @project.repository.after_create if @project.empty_repo? - @project.repository.after_push_commit(branch_name, params[:newrev]) + @project.repository.after_push_commit(branch_name) if push_remove_branch? @project.repository.after_remove_branch @@ -51,12 +51,32 @@ class GitPushService < BaseService execute_related_hooks perform_housekeeping + + update_caches end def update_gitattributes @project.repository.copy_gitattributes(params[:ref]) end + def update_caches + if is_default_branch? + paths = Set.new + + @push_commits.each do |commit| + commit.raw_diffs(deltas_only: true).each do |diff| + paths << diff.new_path + end + end + + types = Gitlab::FileDetector.types_in_paths(paths.to_a) + else + types = [] + end + + ProjectCacheWorker.perform_async(@project.id, types) + end + protected def execute_related_hooks @@ -70,7 +90,6 @@ class GitPushService < BaseService @project.execute_hooks(build_push_data.dup, :push_hooks) @project.execute_services(build_push_data.dup, :push_hooks) Ci::CreatePipelineService.new(@project, current_user, build_push_data).execute - ProjectCacheWorker.perform_async(@project.id) if push_remove_branch? AfterBranchDeleteService |