New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix reading list counter #10763
Fix reading list counter #10763
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for tackling this bug. Code looks pretty good, I left one suggestion, let me know what you think!
| @@ -0,0 +1,5 @@ | |||
| class AddLastChangedArchiveAtToUser < ActiveRecord::Migration[6.0] | |||
| def change | |||
| add_column :users, :last_changed_archive_at, :datetime, default: "2017-01-01 05:00:00" | |||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am not a huge fan of adding another "cache" focused column to user but I cant think about a better way to do this.
What do you think of making this a more general column so we could use it for other caches as well? I was thinking last_reacted_at which would fit nicely with our pattern of last_followed_at, last_article_at etc.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for your comments.
I am not a huge fan of adding another "cache" focused column to user
Neither am I. There are already a bunch of cache keys.
What do you think of making this a more general column so we could use it for other caches as well? I was thinking last_reacted_at which would fit nicely with our pattern of last_followed_at, last_article_at etc.
That’s a new idea for me. At least, I think that it is better than mine as we do not need to add a column whenever something related to a user needs to be cached.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Small suggestion for the spec but otherwise this LGTM!!!!
| @@ -22,11 +22,13 @@ | |||
| it "returns archives item if no param" do | |||
| put "/reading_list_items/#{reaction.id}" | |||
| expect(reaction.reload.status).to eq("archived") | |||
| expect(user.last_reacted_at).not_to eq(user.reload.last_reacted_at) | |||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Rather than relying on ActiveRecord to local memoize this here, I think a cleaner approach would be.
original_reacted_at = user.last_reacted_at
put "/reading_list_items/#{reaction.id}"
expect(reaction.reload.status).to eq("archived")
expect(original_reacted_at).not_to eq(user.reload.last_reacted_at)Same with the example below.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We could also use an actual change assertion here:
expect do
put "/reading_list_items/#{reaction.id}"
end.to change { user.reload.last_reacted_at }
expect(reaction.reload.status).to eq("archived")There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have never thought of being able to use change by giving put "..." to expect as a block. Thank you!
3cda0a2
to
8382369
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks like there's a small conflict that needs to be resolved. Otherwise, LGTM! Thank you so much, I'm looking forward to this fix 🎉 .
What type of PR is this? (check all applicable)
Description
I found that a wrong reading list count was caused by caching. The cache of cached_reading_list_article_ids is changed only when
public_reactions_countis updated, but we must also recache it when user archives and unarchives an article.To achieve this, I added the
last_changed_archive_atcolumn to the users table and cache keys.I could not come up with an idea to fix this without adding an extra column. Will you let me know If you have better thoughts, I'll give it a try.
Related Tickets & Documents
Closes #9770
QA Instructions, Screenshots, Recordings
Please replace this line with instructions on how to test your changes, as well
as any relevant images for UI changes.
Added tests?
Added to documentation?
[optional] Are there any post deployment tasks we need to perform?
[optional] What gif best describes this PR or how it makes you feel?