Skip to content

Instantly share code, notes, and snippets.

@tigris
Created August 19, 2013 07:26
Show Gist options
  • Save tigris/6266481 to your computer and use it in GitHub Desktop.
Save tigris/6266481 to your computer and use it in GitHub Desktop.
rails caching bug
Site -> has_many :pages
> Rails.cache.fetch('test') { a = Array.new ; Site.all.each{|s| a.push(s) if s.pages.count > 1 } ; a }
Site Load (0.7ms) SELECT "sites".* FROM "sites"
(0.7ms) SELECT COUNT(*) FROM "pages" WHERE "pages"."site_id" = 2
(0.7ms) SELECT COUNT(*) FROM "pages" WHERE "pages"."site_id" = 1
=> [#<Site id: 2, designer_id: 4, url: "http://tigris.id.au/", created_at: "2012-09-11 01:18:07", updated_at: "2012-09-11 01:18:07">, #<Site id: 1, designer_id: 1, url: "http://tigris.id.au/", created_at: "2012-09-02 16:39:54", updated_at: "2013-08-01 03:15:47">]
> Rails.cache.fetch('test') { a = Array.new ; Site.all.each{|s| a.push(s) if s.pages.count > 1 } ; a }
=> [#<Site id: 2, designer_id: 4, url: "http://tigris.id.au/", created_at: "2012-09-11 01:18:07", updated_at: "2012-09-11 01:18:07">, :@new_record, false]
League -> has_many :teams
> Rails.cache.fetch('test') { a = Array.new ; League.all.each{|l| a.push(l) if l.teams.count > 1 } ; a }
League Load (1.1ms) SELECT "leagues".* FROM "leagues"
(0.7ms) SELECT COUNT(*) FROM "teams" WHERE "teams"."league_id" = $1 [["league_id", 1]]
(1.3ms) SELECT COUNT(*) FROM "teams" WHERE "teams"."league_id" = $1 [["league_id", 2]]
=> [#<League id: 1, name: "Bamfy FFL", host: "ffl.tigris.id.au", team_limit: 10, rounds: 22>, #<League id: 2, name: "FantasyFL", host: "ffl2.tigris.id.au", team_limit: 8, rounds: 23>]
> Rails.cache.fetch('test') { a = Array.new ; League.all.each{|l| a.push(l) if l.teams.count > 1 } ; a }
=> [#<League id: 1, name: "Bamfy FFL", host: "ffl.tigris.id.au", team_limit: 10, rounds: 22>, #<League id: 2, name: "FantasyFL", host: "ffl2.tigris.id.au", team_limit: 8, rounds: 23>]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment