diff --git a/app/models/account.rb b/app/models/account.rb index 42b641b8b9d..1a5f2b3aa0f 100644 --- a/app/models/account.rb +++ b/app/models/account.rb @@ -311,7 +311,7 @@ class Account < ActiveRecord::Base end def self.account_lookup_cache_key(id) - ['_account_lookup', id].cache_key + ['_account_lookup2', id].cache_key end def find_user_by_unique_id(unique_id) diff --git a/app/models/account_notification.rb b/app/models/account_notification.rb index 13eb1a47c1c..e7492b48318 100644 --- a/app/models/account_notification.rb +++ b/app/models/account_notification.rb @@ -27,7 +27,7 @@ class AccountNotification < ActiveRecord::Base closed_ids = (user && user.preferences[:closed_notifications]) || [] now = Time.now.utc # Refreshes every 10 minutes at the longest - current = AccountNotification.find_all_cached(['account_notifications', account, (now.to_i / 600).to_s].cache_key) do + current = Rails.cache.fetch(['account_notifications2', account].cache_key, :expires_in => 10.minutes) do AccountNotification.find(:all, :conditions => ['account_id IN (?,?) AND start_at < ? AND end_at > ?', Account.site_admin.id, account.id, now, now], :order => 'start_at DESC') end current ||= [] diff --git a/app/models/user.rb b/app/models/user.rb index b6d9c055912..430b835b23d 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -477,7 +477,7 @@ class User < ActiveRecord::Base end def self.user_lookup_cache_key(id) - ['_user_lookup', id].cache_key + ['_user_lookup2', id].cache_key end def self.invalidate_cache(id) @@ -527,7 +527,7 @@ class User < ActiveRecord::Base def self.cached_name(id) key = user_lookup_cache_key(id) - user = find_cached(key) do + user = Rails.cache.fetch(key) do User.find_by_id(id) end user && user.name diff --git a/config/initializers/active_record.rb b/config/initializers/active_record.rb index 5281d4049c3..9091e094d69 100644 --- a/config/initializers/active_record.rb +++ b/config/initializers/active_record.rb @@ -57,42 +57,6 @@ class ActiveRecord::Base res end - def self.find_cached(key, opts = nil, &block) - attrs = Rails.cache.read(key) - if !attrs || attrs.empty? || attrs.is_a?(String) || attrs[:assigned_cache_key] != key - obj = block.call rescue nil - attrs = obj && obj.is_a?(self) ? obj.attributes : nil - attrs[:assigned_cache_key] = key if attrs - Rails.cache.write(key, attrs, opts) if attrs - end - return nil if !attrs || attrs.empty? - obj = self.new - attrs = attrs.dup if attrs.frozen? - attrs.delete(:assigned_cache_key) - obj.instance_variable_set("@attributes", attrs) - obj.instance_variable_set("@new_record", false) - obj - end - - def self.find_all_cached(key, opts = nil, &block) - attrs_list = Rails.cache.read(key) - if !attrs_list || attrs_list.empty? || !attrs_list.is_a?(Array) || attrs_list.any?{|attr| attr[:assigned_cache_key] != key } - list = block.call.to_a rescue nil - attrs_list = list.map{|obj| obj && obj.is_a?(self) ? obj.attributes : nil }.compact - attrs_list.each{|attrs| attrs[:assigned_cache_key] = key } - Rails.cache.write(key, attrs_list, opts) - end - return [] if !attrs_list || attrs_list.empty? - attrs_list.map do |attrs| - obj = self.new - attrs = attrs.dup if attrs.frozen? - attrs.delete(:assigned_cache_key) - obj.instance_variable_set("@attributes", attrs) - obj.instance_variable_set("@new_record", false) - obj - end - end - def asset_string @asset_string ||= "#{self.class.base_ar_class.name.underscore}_#{id.to_s}" end