summaryrefslogtreecommitdiff
path: root/app/workers/clear_database_cache_worker.rb
diff options
context:
space:
mode:
authorNick Thomas <nick@gitlab.com>2016-10-06 22:17:11 +0100
committerNick Thomas <nick@gitlab.com>2016-10-07 02:54:25 +0100
commite94cd6fdfe43d9128d37a539cf84f4388c5cf970 (patch)
tree333c35b6a4483ee0e6b2668486a8f8c81091aa90 /app/workers/clear_database_cache_worker.rb
parent4a90e25f0308515bc4f240e82854a364aea47046 (diff)
downloadgitlab-ce-e94cd6fdfe43d9128d37a539cf84f4388c5cf970.tar.gz
Add markdown cache columns to the database, but don't use them yet
This commit adds a number of _html columns and, with the exception of Note, starts updating them whenever the content of their partner fields changes. Note has a collision with the note_html attr_accessor; that will be fixed later A background worker for clearing these cache columns is also introduced - use `rake cache:clear` to set it off. You can clear the database or Redis caches separately by running `rake cache:clear:db` or `rake cache:clear:redis`, respectively.
Diffstat (limited to 'app/workers/clear_database_cache_worker.rb')
-rw-r--r--app/workers/clear_database_cache_worker.rb23
1 files changed, 23 insertions, 0 deletions
diff --git a/app/workers/clear_database_cache_worker.rb b/app/workers/clear_database_cache_worker.rb
new file mode 100644
index 00000000000..c541daba50e
--- /dev/null
+++ b/app/workers/clear_database_cache_worker.rb
@@ -0,0 +1,23 @@
+# This worker clears all cache fields in the database, working in batches.
+class ClearDatabaseCacheWorker
+ include Sidekiq::Worker
+
+ 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