Commit 67ca5a53 authored by Dmitriy Zaporozhets's avatar Dmitriy Zaporozhets

Build missing cache items in background job after each push

Signed-off-by: default avatarDmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>
parent 881fbe50
......@@ -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
......
......@@ -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
......
......@@ -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
......
class ProjectCacheWorker
include Sidekiq::Worker
sidekiq_options queue: :default
def perform(project_id)
Project.find(project_id).repository.build_cache
end
end
......@@ -18,4 +18,8 @@ class RepositoryCache
def fetch(key, &block)
backend.fetch(cache_key(key), &block)
end
def exist?(key)
backend.exist?(key)
end
end
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment