Commit e9819de1 authored by Nick Thomas's avatar Nick Thomas

Remove the ClearDatabaseCacheWorker

parent 6647542c
...@@ -30,28 +30,6 @@ module CacheMarkdownField ...@@ -30,28 +30,6 @@ module CacheMarkdownField
end end
end end
# Dynamic registries don't really work in Rails as it's not guaranteed that
# every class will be loaded, so hardcode the list.
CACHING_CLASSES = %w[
AbuseReport
Appearance
ApplicationSetting
BroadcastMessage
Issue
Label
MergeRequest
Milestone
Namespace
Note
Project
Release
Snippet
].freeze
def self.caching_classes
CACHING_CLASSES.map(&:constantize)
end
def skip_project_check? def skip_project_check?
false false
end end
...@@ -107,9 +85,6 @@ module CacheMarkdownField ...@@ -107,9 +85,6 @@ module CacheMarkdownField
# a corresponding _html field. Any custom rendering options may be provided # a corresponding _html field. Any custom rendering options may be provided
# as a context. # as a context.
def cache_markdown_field(markdown_field, context = {}) def cache_markdown_field(markdown_field, context = {})
raise "Add #{self} to CacheMarkdownField::CACHING_CLASSES" unless
CacheMarkdownField::CACHING_CLASSES.include?(self.to_s)
cached_markdown_fields[markdown_field] = context cached_markdown_fields[markdown_field] = context
html_field = cached_markdown_fields.html_field(markdown_field) html_field = cached_markdown_fields.html_field(markdown_field)
......
# This worker clears all cache fields in the database, working in batches.
class ClearDatabaseCacheWorker
include Sidekiq::Worker
include DedicatedSidekiqQueue
BATCH_SIZE = 1000
def perform
CacheMarkdownField.caching_classes.each do |kls|
fields = kls.cached_markdown_fields.html_fields
clear_cache_fields = fields.each_with_object({}) do |field, memo|
memo[field] = nil
end
Rails.logger.debug("Clearing Markdown cache for #{kls}: #{fields.inspect}")
kls.unscoped.in_batches(of: BATCH_SIZE) do |relation|
relation.update_all(clear_cache_fields)
end
end
nil
end
end
...@@ -34,7 +34,6 @@ ...@@ -34,7 +34,6 @@
- [repository_fork, 1] - [repository_fork, 1]
- [repository_import, 1] - [repository_import, 1]
- [project_service, 1] - [project_service, 1]
- [clear_database_cache, 1]
- [delete_user, 1] - [delete_user, 1]
- [delete_merged_branches, 1] - [delete_merged_branches, 1]
- [authorized_projects, 1] - [authorized_projects, 1]
......
...@@ -21,12 +21,7 @@ namespace :cache do ...@@ -21,12 +21,7 @@ namespace :cache do
end end
end end
desc "GitLab | Clear database cache (in the background)" task all: [:redis]
task db: :environment do
ClearDatabaseCacheWorker.perform_async
end
task all: [:db, :redis]
end end
task clear: 'cache:clear:redis' task clear: 'cache:clear:redis'
......
require 'spec_helper' require 'spec_helper'
describe CacheMarkdownField do describe CacheMarkdownField do
caching_classes = CacheMarkdownField::CACHING_CLASSES
CacheMarkdownField::CACHING_CLASSES = ["ThingWithMarkdownFields"].freeze
# The minimum necessary ActiveModel to test this concern # The minimum necessary ActiveModel to test this concern
class ThingWithMarkdownFields class ThingWithMarkdownFields
include ActiveModel::Model include ActiveModel::Model
...@@ -55,8 +52,6 @@ describe CacheMarkdownField do ...@@ -55,8 +52,6 @@ describe CacheMarkdownField do
end end
end end
CacheMarkdownField::CACHING_CLASSES = caching_classes
def thing_subclass(new_attr) def thing_subclass(new_attr)
Class.new(ThingWithMarkdownFields) { add_attr(new_attr) } Class.new(ThingWithMarkdownFields) { add_attr(new_attr) }
end end
...@@ -69,15 +64,9 @@ describe CacheMarkdownField do ...@@ -69,15 +64,9 @@ describe CacheMarkdownField do
subject { ThingWithMarkdownFields.new(foo: markdown, foo_html: html) } subject { ThingWithMarkdownFields.new(foo: markdown, foo_html: html) }
describe ".attributes" do describe '.attributes' do
it "excludes cache attributes" do it 'excludes cache attributes' do
expect(thing_subclass(:qux).new.attributes.keys.sort).to eq(%w[bar baz foo qux]) expect(subject.attributes.keys.sort).to eq(%w[bar baz foo])
end
end
describe ".cache_markdown_field" do
it "refuses to allow untracked classes" do
expect { thing_subclass(:qux).__send__(:cache_markdown_field, :qux) }.to raise_error(RuntimeError)
end end
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