Optimize impressionist_count query via arel count with distinct option
This commit is contained in:
1 parent
594889a3db
commit
fcfacdfdc9
2 files changed
+2
-5
No files matched your search
@@ -26,10 +26,7 @@ module Impressionist
|
||||
def impressionist_count(options={})
|
||||
options.reverse_merge!(:filter=>:request_hash, :start_date=>nil, :end_date=>Time.now)
|
||||
imps = options[:start_date].blank? ? impressions : impressions.where("created_at>=? and created_at<=?",options[:start_date],options[:end_date])
|
||||
if options[:filter]!=:all
|
||||
imps = imps.select(options[:filter]).group(options[:filter])
|
||||
end
|
||||
imps.all.size
|
||||
options[:filter] == :all ? imps.count : imps.count(options[:filter], :distinct => true)
|
||||
end
|
||||
|
||||
def update_counter_cache
|
||||
|
||||
Reference in new issue
Block a user