Despite the performance problems discussed in my other issue here:
I will give impressionist a try again in a new project. However, there are some problems.
I can't get impressionist to keep unique impressions in the counter cache.
I have this in my controller:
@photo = Photo.find(params[:id]).decorate
is_impressionable counter_cache: true, unique: true
Still, it logs a new impression in my counter cache (called impressions_count) every time I refresh the page. Shouldn't it be filtering on the IP-adress by default when setting unique: true?
I'm using Rails 4 and impressionist 1.4.5
Something seems really off here...
If I run: photo.impressionist_count(:filter => :session_hash) it counts all impressions, although I can see they have the same session_hash.
photo.impressionist_count(:filter => :session_hash)
I get the same result with filter: :ip_address
The SQL generated looks like this:
SELECT COUNT("impressions"."ip_address") FROM "impressions" WHERE "impressions"."impressionable_id" = $1 AND "impressions"."impressionable_type" = $2 [["impressionable_id", 27], ["impressionable_type", "Photo"]]
I guess there should be a DISTINCT thrown in there as well to make it work.
Impressionist seems to call something like this:
imps.count(:ip_address, distinct: true)
This doesn't seem to work. At least not in Rails 4. How about doing something like this instead:
This works in Rails 4 but the .distinct� call does not exist in Rails 3 but instead you'd use .uniq
But the .uniq call seems to raise some issues: rails/rails#7399
So, perhaps just check rails version and keep the current solution if < 4.0 otherwise go with the above?