From e5293f2c9a3fa1a7ee71f1191d62e50d21ad76bb Mon Sep 17 00:00:00 2001 From: Robin Ward Date: Thu, 7 Jul 2016 16:27:18 -0400 Subject: [PATCH] FIX: Force HTML to recompile --- app/models/site_customization.rb | 21 ++++++++++++++++--- ...compiler_version_to_site_customizations.rb | 5 +++++ 2 files changed, 23 insertions(+), 3 deletions(-) create mode 100644 db/migrate/20160707195549_add_compiler_version_to_site_customizations.rb diff --git a/app/models/site_customization.rb b/app/models/site_customization.rb index 57bc6319d00..5978892f40f 100644 --- a/app/models/site_customization.rb +++ b/app/models/site_customization.rb @@ -4,6 +4,9 @@ require_dependency 'distributed_cache' class SiteCustomization < ActiveRecord::Base ENABLED_KEY = '7e202ef2-56d7-47d5-98d8-a9c8d15e57dd' + + COMPILER_VERSION = 1 + @cache = DistributedCache.new('site_customization') def self.css_fields @@ -131,7 +134,7 @@ COMPILED end def self.enabled_stylesheet_contents(target=:desktop) - @cache["enabled_stylesheet_#{target}"] ||= where(enabled: true) + @cache["enabled_stylesheet_#{target}:#{COMPILER_VERSION}"] ||= where(enabled: true) .order(:name) .pluck(baked_for_target(target)) .compact @@ -167,7 +170,7 @@ COMPILED def self.lookup_field(key, target, field) return if key.blank? - cache_key = key + target.to_s + field.to_s; + cache_key = "#{key}:#{target}:#{field}:#{COMPILER_VERSION}" lookup = @cache[cache_key] return lookup.html_safe if lookup @@ -203,7 +206,19 @@ COMPILED end def ensure_baked!(field) - unless self.send("#{field}_baked") + + # If the version number changes, clear out all the baked fields + if compiler_version != COMPILER_VERSION + updates = { compiler_version: COMPILER_VERSION } + SiteCustomization.html_fields.each do |f| + updates["#{f}_baked".to_sym] = nil + end + + update_columns(updates) + end + + baked = send("#{field}_baked") + if baked.blank? if val = self.send(field) val = process_html(val) rescue "" self.update_columns("#{field}_baked" => val) diff --git a/db/migrate/20160707195549_add_compiler_version_to_site_customizations.rb b/db/migrate/20160707195549_add_compiler_version_to_site_customizations.rb new file mode 100644 index 00000000000..6abab5f72f5 --- /dev/null +++ b/db/migrate/20160707195549_add_compiler_version_to_site_customizations.rb @@ -0,0 +1,5 @@ +class AddCompilerVersionToSiteCustomizations < ActiveRecord::Migration + def change + add_column :site_customizations, :compiler_version, :integer, default: 0, null: false + end +end