summaryrefslogtreecommitdiff
path: root/app/models/concerns/cache_markdown_field.rb
diff options
context:
space:
mode:
authorToon Claes <toon@iotcl.com>2017-09-19 09:44:58 +0200
committerToon Claes <toon@iotcl.com>2017-10-06 22:37:40 +0200
commitd13669716ab0c31ce9039ae9f7f073e33a4dc40f (patch)
tree001bb2e6aa76ea7531c93e469c396f7fdcc408a7 /app/models/concerns/cache_markdown_field.rb
parent2cf5dca8f80cdefeb8932bf80417f52f289668c8 (diff)
downloadgitlab-ce-d13669716ab0c31ce9039ae9f7f073e33a4dc40f.tar.gz
Create idea of read-only databasetc-geo-read-only-idea
In GitLab EE, a GitLab instance can be read-only (e.g. when it's a Geo secondary node). But in GitLab CE it also might be useful to have the "read-only" idea around. So port it back to GitLab CE. Also having the principle of read-only in GitLab CE would hopefully lead to less errors introduced, doing write operations when there aren't allowed for read-only calls. Closes gitlab-org/gitlab-ce#37534.
Diffstat (limited to 'app/models/concerns/cache_markdown_field.rb')
-rw-r--r--app/models/concerns/cache_markdown_field.rb14
1 files changed, 10 insertions, 4 deletions
diff --git a/app/models/concerns/cache_markdown_field.rb b/app/models/concerns/cache_markdown_field.rb
index 193e459977a..9417033d1f6 100644
--- a/app/models/concerns/cache_markdown_field.rb
+++ b/app/models/concerns/cache_markdown_field.rb
@@ -59,7 +59,7 @@ module CacheMarkdownField
# Update every column in a row if any one is invalidated, as we only store
# one version per row
- def refresh_markdown_cache!(do_update: false)
+ def refresh_markdown_cache
options = { skip_project_check: skip_project_check? }
updates = cached_markdown_fields.markdown_fields.map do |markdown_field|
@@ -71,8 +71,14 @@ module CacheMarkdownField
updates['cached_markdown_version'] = CacheMarkdownField::CACHE_VERSION
updates.each {|html_field, data| write_attribute(html_field, data) }
+ end
+
+ def refresh_markdown_cache!
+ updates = refresh_markdown_cache
+
+ return unless persisted? && Gitlab::Database.read_write?
- update_columns(updates) if persisted? && do_update
+ update_columns(updates)
end
def cached_html_up_to_date?(markdown_field)
@@ -124,8 +130,8 @@ module CacheMarkdownField
end
# Using before_update here conflicts with elasticsearch-model somehow
- before_create :refresh_markdown_cache!, if: :invalidated_markdown_cache?
- before_update :refresh_markdown_cache!, if: :invalidated_markdown_cache?
+ before_create :refresh_markdown_cache, if: :invalidated_markdown_cache?
+ before_update :refresh_markdown_cache, if: :invalidated_markdown_cache?
end
class_methods do