forked from codetriage/CodeTriage
- Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcache_version.rb
45 lines (34 loc) · 840 Bytes
/
cache_version.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# frozen_string_literal: true
require"active_record"
ActiveRecord::Base.establish_connection(adapter: "sqlite3",database: ":memory:")
ActiveRecord::Base.cache_versioning=true
ActiveRecord::Schema.definedo
create_table:users,force: truedo |t|
t.string:name
t.timestampsnull: false
end
create_table:topics,force: truedo |t|
t.string:title
t.integer:user_id
t.timestampsnull: false
end
end
classTopic < ActiveRecord::Base
belongs_to:user
end
classUser < ActiveRecord::Base
has_many:topics
end
mass_user_create=1000.times.each.mapdo
{name: "user"}
end
User.create(mass_user_create)
ALL_USERS=User.all
putsALL_USERS.first.method(:cache_version).source_location
Benchmark.bm{ |x|
x.report("title_was"){
ALL_USERS.eachdo |user|
user.cache_version
end
}
}