You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hello, our model has messages that belong to groups and we want to track the group's outbound message count, but only count messages for each recipient once per group (sending a message to the same recipient in the same group multiple times should only increment the groups message count once).
To do this our dynamic column count looked like this:
After we create the message which increments the counter by 1, we send it off to Sidekiq where it is updated with it's delivery timestamp. At this point, the counter increments to 2.
This gem uses ActiveRecord's dup to check if the cache column has changed after each update. dup does not copy the record's ID, instead it sets id to nil. Because of that, the cache column was always "changing" as the dynamic column was checking where id IS NOT NULL, unexpectedly leading to a nil column name vs. the non-dupes column name of messages_count.
I am not sure of the proper fix or if there was a better way to get this functionality without running into this issue, but at the very least I'd like to document this behavior here for the next person as it was quite the goose chase.
The text was updated successfully, but these errors were encountered:
Thanks, but this seems quite specific to your particular use of this. Going to close the issue since I don't think this is a problem with counter_culture.
OK. To summarize though, using id in your column name logic is broken as it will always evaluate to nil. I do think that it is a problem with counter_culture but one that may not be worth fixing. I can live with that 👍
Hello, our model has messages that belong to groups and we want to track the group's outbound message count, but only count messages for each recipient once per group (sending a message to the same recipient in the same group multiple times should only increment the groups message count once).
To do this our dynamic column count looked like this:
After we create the message which increments the counter by 1, we send it off to Sidekiq where it is updated with it's delivery timestamp. At this point, the counter increments to 2.
This gem uses ActiveRecord's
dup
to check if the cache column has changed after each update.dup
does not copy the record's ID, instead it sets id tonil
. Because of that, the cache column was always "changing" as the dynamic column was checkingwhere id IS NOT NULL
, unexpectedly leading to anil
column name vs. the non-dupes column name ofmessages_count
.I am not sure of the proper fix or if there was a better way to get this functionality without running into this issue, but at the very least I'd like to document this behavior here for the next person as it was quite the goose chase.
The text was updated successfully, but these errors were encountered: