Skip to content
Snippets Groups Projects
Unverified Commit 67ca5a53 authored by Dmitriy Zaporozhets's avatar Dmitriy Zaporozhets
Browse files

Build missing cache items in background job after each push

parent 881fbe50
No related branches found
No related tags found
No related merge requests found
Loading
@@ -130,10 +130,29 @@ class Repository
Loading
@@ -130,10 +130,29 @@ class Repository
cache.fetch(:size) { raw_repository.size } cache.fetch(:size) { raw_repository.size }
end end
   
def expire_cache def cache_keys
%i(size branch_names tag_names commit_count graph_log %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) cache.expire(key)
send(key)
end end
end end
   
Loading
Loading
Loading
@@ -61,6 +61,7 @@ class GitPushService
Loading
@@ -61,6 +61,7 @@ class GitPushService
EventCreateService.new.push(project, user, @push_data) EventCreateService.new.push(project, user, @push_data)
project.execute_hooks(@push_data.dup, :push_hooks) project.execute_hooks(@push_data.dup, :push_hooks)
project.execute_services(@push_data.dup, :push_hooks) project.execute_services(@push_data.dup, :push_hooks)
ProjectCacheWorker.perform_async(project.id)
end end
   
protected protected
Loading
Loading
Loading
@@ -2,15 +2,15 @@ class GitTagPushService
Loading
@@ -2,15 +2,15 @@ class GitTagPushService
attr_accessor :project, :user, :push_data attr_accessor :project, :user, :push_data
   
def execute(project, user, oldrev, newrev, ref) 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) @push_data = build_push_data(oldrev, newrev, ref)
   
EventCreateService.new.push(project, user, @push_data) EventCreateService.new.push(project, user, @push_data)
project.execute_hooks(@push_data.dup, :tag_push_hooks) project.execute_hooks(@push_data.dup, :tag_push_hooks)
project.execute_services(@push_data.dup, :tag_push_hooks) project.execute_services(@push_data.dup, :tag_push_hooks)
ProjectCacheWorker.perform_async(project.id)
project.repository.expire_cache
   
true true
end end
Loading
Loading
class ProjectCacheWorker
include Sidekiq::Worker
sidekiq_options queue: :default
def perform(project_id)
Project.find(project_id).repository.build_cache
end
end
Loading
@@ -18,4 +18,8 @@ class RepositoryCache
Loading
@@ -18,4 +18,8 @@ class RepositoryCache
def fetch(key, &block) def fetch(key, &block)
backend.fetch(cache_key(key), &block) backend.fetch(cache_key(key), &block)
end end
def exist?(key)
backend.exist?(key)
end
end end
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment