2
0
Fork 0
mirror of https://github.com/discourse/discourse.git synced 2025-09-11 21:04:42 +08:00

FEATURE: move stylesheet cache out of the uploads directory

This commit is contained in:
Sam 2015-05-05 15:50:13 +10:00
parent 8e372f3616
commit f58d85edea
8 changed files with 105 additions and 6 deletions

View file

@ -0,0 +1,25 @@
class StylesheetCache < ActiveRecord::Base
self.table_name = 'stylesheet_cache'
MAX_TO_KEEP = 10
def self.add(target,digest,content)
success = create(target: target, digest: digest, content: content)
count = StylesheetCache.count
if count > MAX_TO_KEEP
remove_lower = StylesheetCache.limit(MAX_TO_KEEP)
.order('id desc')
.pluck(:id)
.last
exec_sql("DELETE FROM stylesheet_cache where id < :id", id: remove_lower)
end
success
rescue ActiveRecord::RecordNotUnique
false
end
end