Commit 2e4a673c authored by Jason Lee's avatar Jason Lee

Add caching for ApplicationSetting, Ci::ApplicationSetting.

ApplicationSetting.current was called in every pages, cache it and expires it after it updated.

This changes will avoid a SQL query in every pages (~0.3 - 0.5ms).

```SQL
SELECT  "application_settings".* FROM "application_settings"   ORDER BY "application_settings"."id" DESC LIMIT 1
```
parent ca25289b
......@@ -68,8 +68,14 @@ class ApplicationSetting < ActiveRecord::Base
end
end
after_commit do
Rails.cache.write('application_setting.last', self)
end
def self.current
ApplicationSetting.last
Rails.cache.fetch('application_setting.last') do
ApplicationSetting.last
end
end
def self.create_from_defaults
......
......@@ -12,9 +12,15 @@
module Ci
class ApplicationSetting < ActiveRecord::Base
extend Ci::Model
after_commit do
Rails.cache.write('ci_application_setting.last', self)
end
def self.current
Ci::ApplicationSetting.last
Rails.cache.fetch('ci_application_setting.last') do
Ci::ApplicationSetting.last
end
end
def self.create_from_defaults
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment