diff options
author | Dmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com> | 2015-07-17 15:50:03 +0300 |
---|---|---|
committer | Dmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com> | 2015-07-17 15:50:03 +0300 |
commit | 67ca5a53f6df0c3d0f2598c777491c0548d76e50 (patch) | |
tree | adbd12e3b93c6f79335625dd2769843e15676341 /app | |
parent | 881fbe5070331f934fff3441dbc0e65377b030bf (diff) |
Build missing cache items in background job after each push
Signed-off-by: Dmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>
Diffstat (limited to 'app')
-rw-r--r-- | app/models/repository.rb | 23 | ||||
-rw-r--r-- | app/services/git_push_service.rb | 1 | ||||
-rw-r--r-- | app/services/git_tag_push_service.rb | 6 | ||||
-rw-r--r-- | app/workers/project_cache_worker.rb | 9 |
4 files changed, 34 insertions, 5 deletions
diff --git a/app/models/repository.rb b/app/models/repository.rb index 6262b5c4c92..bca14aa1a33 100644 --- a/app/models/repository.rb +++ b/app/models/repository.rb @@ -130,10 +130,29 @@ class Repository cache.fetch(:size) { raw_repository.size } end - def expire_cache + def cache_keys %i(size branch_names tag_names commit_count graph_log - readme version contribution_guide changelog license).each do |key| + readme version contribution_guide changelog license) + end + + def build_cache + cache_keys.each do |key| + unless cache.exist?(key) + send(key) + end + end + end + + def expire_cache + cache_keys.each do |key| + cache.expire(key) + end + end + + def rebuild_cache + cache_keys.each do |key| cache.expire(key) + send(key) end end diff --git a/app/services/git_push_service.rb b/app/services/git_push_service.rb index 6135ae65007..c36113329ea 100644 --- a/app/services/git_push_service.rb +++ b/app/services/git_push_service.rb @@ -61,6 +61,7 @@ class GitPushService EventCreateService.new.push(project, user, @push_data) project.execute_hooks(@push_data.dup, :push_hooks) project.execute_services(@push_data.dup, :push_hooks) + ProjectCacheWorker.perform_async(project.id) end protected diff --git a/app/services/git_tag_push_service.rb b/app/services/git_tag_push_service.rb index 075a6118da2..1cc42b0b0ad 100644 --- a/app/services/git_tag_push_service.rb +++ b/app/services/git_tag_push_service.rb @@ -2,15 +2,15 @@ class GitTagPushService attr_accessor :project, :user, :push_data def execute(project, user, oldrev, newrev, ref) - @project, @user = project, user + project.repository.expire_cache + @project, @user = project, user @push_data = build_push_data(oldrev, newrev, ref) EventCreateService.new.push(project, user, @push_data) project.execute_hooks(@push_data.dup, :tag_push_hooks) project.execute_services(@push_data.dup, :tag_push_hooks) - - project.repository.expire_cache + ProjectCacheWorker.perform_async(project.id) true end diff --git a/app/workers/project_cache_worker.rb b/app/workers/project_cache_worker.rb new file mode 100644 index 00000000000..4c14565dce5 --- /dev/null +++ b/app/workers/project_cache_worker.rb @@ -0,0 +1,9 @@ +class ProjectCacheWorker + include Sidekiq::Worker + + sidekiq_options queue: :default + + def perform(project_id) + Project.find(project_id).repository.build_cache + end +end |