For a social networking site, I have event activity from people you follow, and I would like to group similar types of events made in a short period of time for a more compact activity feed. Imagine how Facebook displays a comma-separated list when you like "a few things in quick succession:" Joe loves beer, football and chips. "
I understand the use of the group_by method in ActiveRecord Enumerable results, but some initial work needs to be started, filling out a property that I can group later. My questions are about how to store activity data so that these groups can be tagged and then returned later.
Now I have an Activity model, which is an association of the connection between the user who performed the action and the element with which it is associated (in my example above, suppose that the “beer”, “football” and “chips” entries of the Like model). There are other types of activity besides “sympathies” (events, preservation of favorites, etc.). What I consider, since this association is created, the check is performed when the last association of this type was performed, and if it was made more than a certain period of time ago, increasing the counter "activity block", which is part of the activity model. Later, when rendering this activity feed, I can group by user, then enter, then this activity counter.
Example: suppose that on the same day 2 blocks of updates were made. The user likes 2 things at 2:05, and then 3 more things at 5:45. After the third update (the beginning of the second block) occurs at 5:45, the model detects too much time and increases the counter of activity blocks by 1, thereby forcing any subsequent updates into a new block when they are displayed through a group_by call:
2:05 Joe likes beer nuts and Hooters. 5:45 Joe likes couches, chips and salsa. 7:00 Joe is attending the Football Viewing Party At Joe's
My first question is: what is an effective way to increase the counter? This is no longer auto_increment, so the easiest thing I can think of is looking at the counter for the last record as a checkpoint. However, this cannot be from the same query that checked when the last update of this type was made, since a later update of another type could already get the next counter value. They do not have to be globally unique, but that would be nice.
Another common strategy that I was thinking about was another Called ActivityBlock model, which brings together groups of similar actions. In many cases, updates will be isolated on their own, so it seems a little inefficient to have one entry for each individual activity.
Is there any of them as a reliable strategy?
My last question revolves around pagination. Now that we are dealing with blocks, it’s more difficult to always display a precisely defined number of records before being paginated. Either an individual (isolated) activity update, or the block should then be counted as 1, so on the lowest layer of my group_by, I can turn on the counter to track the number of lines that I displayed, but this means that I can’t just just execute one request DB and just specify the restriction operator. Is there a way to do this without having to execute additional SQL queries again until I reach the limit of my page?
This would be one of the benefits of the ActivityBlock model approach, since I could easily apply a call limit to it, and the blocks could also contain an auto-increment counter.