Permalink
Browse files

Revert "Removing cached_find"

This reverts commit 4e08e1b.

Conflicts:

	lib/a_b/model/variant.rb
  • Loading branch information...
1 parent 8969a90 commit 93b95cbfb1360eb990b9cbfe3cf2c7d5f2f7e2a7 @winton committed Nov 8, 2010
@@ -0,0 +1,9 @@
+class RemoveVariantsLock < ActiveRecord::Migration
+ def self.up
+ remove_column :variants, :lock_version
+ end
+
+ def self.down
+ add_column :variants, :lock_version, :integer, :default => 0
+ end
+end
@@ -0,0 +1,10 @@
+require 'pp'
+
+module CachedFind
+
+ def cached_find(*args)
+ $cached_find ||= {}
+ cache = $cached_find[self.to_s.intern] ||= {}
+ cache[args.pretty_inspect] ||= self.find(*args)
+ end
+end
View
@@ -1,5 +1,7 @@
class Env < ActiveRecord::Base
+ extend CachedFind
+
belongs_to :site
belongs_to :user
View
@@ -1,5 +1,7 @@
class Variant < ActiveRecord::Base
+ extend CachedFind
+
belongs_to :category
belongs_to :site
belongs_to :test, :class_name => 'ABTest', :foreign_key => 'test_id'
@@ -42,9 +44,11 @@ def self.record(options)
ids = data['c'] + data['v']
ids = ids.compact.uniq
- variants = Variant.find_all_by_id(ids, :include => :site)
+ variants = ids.collect do |id|
+ Variant.cached_find(id, :include => :site)
+ end
- env = Env.find(:first, :conditions => {
+ env = Env.cached_find(:first, :conditions => {
:name => env,
:user_id => variants[0].user_id
})
@@ -3,6 +3,7 @@
describe Env do
before(:each) do
+ $cached_find = nil
teardown_tests
setup_tests
end
@@ -3,6 +3,7 @@
describe Variant do
before(:each) do
+ $cached_find = nil
teardown_tests
setup_tests
end

0 comments on commit 93b95cb

Please sign in to comment.