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:
parent
8e372f3616
commit
f58d85edea
8 changed files with 105 additions and 6 deletions
25
app/models/stylesheet_cache.rb
Normal file
25
app/models/stylesheet_cache.rb
Normal 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
|
Loading…
Add table
Add a link
Reference in a new issue