Skip to content

Commit

Permalink
Do not use the cache for select('distinct ...')
Browse files Browse the repository at this point in the history
  • Loading branch information
orslumen committed Sep 7, 2015
1 parent 52d06b4 commit 5e0e627
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 3 deletions.
2 changes: 1 addition & 1 deletion lib/record_cache/datastore/active_record_30.rb
Expand Up @@ -173,7 +173,7 @@ def visit_Arel_Nodes_SelectCore o
@cacheable = false unless o.groups.empty?
visit o.froms if @cacheable
visit o.wheres if @cacheable
# skip o.projections
@cacheable = o.projections.none?{ |projection| projection.to_s =~ /distinct/i } unless o.projections.empty?
end

def visit_Arel_Nodes_SelectStatement o
Expand Down
2 changes: 1 addition & 1 deletion lib/record_cache/datastore/active_record_31.rb
Expand Up @@ -199,7 +199,7 @@ def visit_Arel_Nodes_SelectCore o
visit o.froms if @cacheable
visit o.wheres if @cacheable
visit o.source if @cacheable
# skip o.projections
@cacheable = o.projections.none?{ |projection| projection.to_s =~ /distinct/i } unless o.projections.empty?
end

def visit_Arel_Nodes_SelectStatement o
Expand Down
2 changes: 1 addition & 1 deletion lib/record_cache/datastore/active_record_32.rb
Expand Up @@ -210,7 +210,7 @@ def visit_Arel_Nodes_SelectCore o
visit o.froms if @cacheable
visit o.wheres if @cacheable
visit o.source if @cacheable
# skip o.projections
@cacheable = o.projections.none?{ |projection| projection.to_s =~ /distinct/i } unless o.projections.empty?
end

def visit_Arel_Nodes_SelectStatement o
Expand Down
4 changes: 4 additions & 0 deletions spec/lib/strategy/unique_index_on_id_cache_spec.rb
Expand Up @@ -99,6 +99,10 @@
it "should not use the cache when a join clause is used" do
expect{ Apple.where(:id => [1,2]).joins(:store).all }.to_not use_cache(Apple).on(:id)
end

it "should not use the cache when distinct is used in a select" do
expect{ Apple.select('distinct person_id').where(:id => [1, 2]).all }.not_to hit_cache(Apple).on(:id)
end
end

context "record_change" do
Expand Down

0 comments on commit 5e0e627

Please sign in to comment.