diff --git a/app/controllers/stylesheets_controller.rb b/app/controllers/stylesheets_controller.rb index ffdf7e02f..af6e34048 100644 --- a/app/controllers/stylesheets_controller.rb +++ b/app/controllers/stylesheets_controller.rb @@ -8,7 +8,7 @@ class StylesheetsController < ApplicationController digest = "_" + digest if digest # Security note, safe due to route constraint - location = "#{DiscourseStylesheets::CACHE_PATH}/#{target}#{digest}.css" + location = "#{Rails.root}/#{DiscourseStylesheets::CACHE_PATH}/#{target}#{digest}.css" unless File.exist?(location) query = StylesheetCache.where(target: target) diff --git a/app/models/stylesheet_cache.rb b/app/models/stylesheet_cache.rb index 9b4f0c5b1..c123e8aad 100644 --- a/app/models/stylesheet_cache.rb +++ b/app/models/stylesheet_cache.rb @@ -20,6 +20,8 @@ class StylesheetCache < ActiveRecord::Base success rescue ActiveRecord::RecordNotUnique false + rescue PG::UniqueViolation + false end end diff --git a/lib/sass/discourse_stylesheets.rb b/lib/sass/discourse_stylesheets.rb index 9d7dbbb8d..7b2b59f6e 100644 --- a/lib/sass/discourse_stylesheets.rb +++ b/lib/sass/discourse_stylesheets.rb @@ -89,7 +89,11 @@ class DiscourseStylesheets File.open(stylesheet_fullpath, "w") do |f| f.puts css end - StylesheetCache.add(@target, digest, css) + begin + StylesheetCache.add(@target, digest, css) + rescue => e + Rails.logger.warn "Completely unexpected error adding item to cache #{e}" + end css end