From bd96abcd1e2dccb06d5460f11bc12b7ddfb11b79 Mon Sep 17 00:00:00 2001 From: Molly Struve Date: Mon, 19 Oct 2020 14:26:19 -0400 Subject: [PATCH] [deploy] Fix Reading List Counter Without last_reacted_at Default (#10933) --- app/controllers/async_info_controller.rb | 1 + app/controllers/reading_list_items_controller.rb | 2 ++ app/models/user.rb | 2 +- db/migrate/20201017160628_add_last_reacted_at_to_user.rb | 5 +++++ db/schema.rb | 1 + spec/requests/reading_list_items_spec.rb | 8 ++++++-- 6 files changed, 16 insertions(+), 3 deletions(-) create mode 100644 db/migrate/20201017160628_add_last_reacted_at_to_user.rb diff --git a/app/controllers/async_info_controller.rb b/app/controllers/async_info_controller.rb index 2d74eb90f..d01dbe2e8 100644 --- a/app/controllers/async_info_controller.rb +++ b/app/controllers/async_info_controller.rb @@ -77,6 +77,7 @@ class AsyncInfoController < ApplicationController #{current_user&.last_sign_in_at}__ #{current_user&.following_tags_count}__ #{current_user&.last_followed_at}__ + #{current_user&.last_reacted_at}__ #{current_user&.updated_at}__ #{current_user&.reactions_count}__ #{current_user&.articles_count}__ diff --git a/app/controllers/reading_list_items_controller.rb b/app/controllers/reading_list_items_controller.rb index f17c1e813..4669da04f 100644 --- a/app/controllers/reading_list_items_controller.rb +++ b/app/controllers/reading_list_items_controller.rb @@ -10,6 +10,8 @@ class ReadingListItemsController < ApplicationController @reaction.status = params[:current_status] == "archived" ? "valid" : "archived" @reaction.save + @reaction.user.touch(:last_reacted_at) + head :ok end diff --git a/app/models/user.rb b/app/models/user.rb index caf0d1f3b..6f0bfee35 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -286,7 +286,7 @@ class User < ApplicationRecord end def cached_reading_list_article_ids - Rails.cache.fetch("reading_list_ids_of_articles_#{id}_#{public_reactions_count}") do + Rails.cache.fetch("reading_list_ids_of_articles_#{id}_#{public_reactions_count}_#{last_reacted_at}") do Reaction.readinglist.where( user_id: id, reactable_type: "Article", ).where.not(status: "archived").order(created_at: :desc).pluck(:reactable_id) diff --git a/db/migrate/20201017160628_add_last_reacted_at_to_user.rb b/db/migrate/20201017160628_add_last_reacted_at_to_user.rb new file mode 100644 index 000000000..c03ddb528 --- /dev/null +++ b/db/migrate/20201017160628_add_last_reacted_at_to_user.rb @@ -0,0 +1,5 @@ +class AddLastReactedAtToUser < ActiveRecord::Migration[6.0] + def change + add_column :users, :last_reacted_at, :datetime + end +end diff --git a/db/schema.rb b/db/schema.rb index 5e78404e5..2c6ef647c 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -1266,6 +1266,7 @@ ActiveRecord::Schema.define(version: 2020_10_19_012200) do t.datetime "last_moderation_notification", default: "2017-01-01 05:00:00" t.datetime "last_notification_activity" t.string "last_onboarding_page" + t.datetime "last_reacted_at" t.datetime "last_sign_in_at" t.inet "last_sign_in_ip" t.string "linkedin_url" diff --git a/spec/requests/reading_list_items_spec.rb b/spec/requests/reading_list_items_spec.rb index f5ab5c364..eddb76e72 100644 --- a/spec/requests/reading_list_items_spec.rb +++ b/spec/requests/reading_list_items_spec.rb @@ -20,12 +20,16 @@ RSpec.describe "ReadingListItems", type: :request do describe "PUT reading_list_items/:id" do it "returns archives item if no param" do - put "/reading_list_items/#{reaction.id}" + expect do + put "/reading_list_items/#{reaction.id}" + end.to change { user.reload.last_reacted_at } expect(reaction.reload.status).to eq("archived") end it "unarchives an item if current_status is passed as archived" do - put "/reading_list_items/#{reaction.id}", params: { current_status: "archived" } + expect do + put "/reading_list_items/#{reaction.id}", params: { current_status: "archived" } + end.to change { user.reload.last_reacted_at } expect(reaction.reload.status).to eq("valid") end