[deploy] Refactor:Remove ReadingList Labor Class, Replace with user Method (#10322)
This commit is contained in:
parent
f2b59cc882
commit
7520caf0e2
5 changed files with 18 additions and 48 deletions
|
|
@ -54,7 +54,7 @@ class AsyncInfoController < ApplicationController
|
|||
followed_tags: @user.cached_followed_tags.to_json(only: %i[id name bg_color_hex text_color_hex hotness_score],
|
||||
methods: [:points]),
|
||||
followed_podcast_ids: @user.cached_following_podcasts_ids,
|
||||
reading_list_ids: ReadingList.new(@user).cached_ids_of_articles,
|
||||
reading_list_ids: @user.cached_reading_list_article_ids,
|
||||
blocked_user_ids: @user.all_blocking.pluck(:blocked_id),
|
||||
saw_onboarding: @user.saw_onboarding,
|
||||
checked_code_of_conduct: @user.checked_code_of_conduct,
|
||||
|
|
@ -77,8 +77,6 @@ class AsyncInfoController < ApplicationController
|
|||
#{current_user&.last_followed_at}__
|
||||
#{current_user&.updated_at}__
|
||||
#{current_user&.reactions_count}__
|
||||
#{current_user&.saw_onboarding}__
|
||||
#{current_user&.checked_code_of_conduct}__
|
||||
#{current_user&.articles_count}__
|
||||
#{current_user&.pro?}__
|
||||
#{current_user&.blocking_others_count}__"
|
||||
|
|
|
|||
|
|
@ -1,21 +0,0 @@
|
|||
class ReadingList
|
||||
attr_accessor :user
|
||||
|
||||
def initialize(user)
|
||||
@user = user
|
||||
end
|
||||
|
||||
def cached_ids_of_articles
|
||||
Rails.cache.fetch("reading_list_ids_of_articles_#{user.id}_#{user.public_reactions_count}") do
|
||||
ids_of_articles
|
||||
end
|
||||
end
|
||||
|
||||
def ids_of_articles
|
||||
Reaction.where(reaction_criteria).where.not(status: "archived").order(created_at: :desc).pluck(:reactable_id)
|
||||
end
|
||||
|
||||
def reaction_criteria
|
||||
{ user_id: user.id, reactable_type: "Article", category: "readinglist" }
|
||||
end
|
||||
end
|
||||
|
|
@ -295,6 +295,14 @@ class User < ApplicationRecord
|
|||
end
|
||||
end
|
||||
|
||||
def cached_reading_list_article_ids
|
||||
Rails.cache.fetch("reading_list_ids_of_articles_#{id}_#{public_reactions_count}") do
|
||||
Reaction.readinglist.where(
|
||||
user_id: id, reactable_type: "Article",
|
||||
).where.not(status: "archived").order(created_at: :desc).pluck(:reactable_id)
|
||||
end
|
||||
end
|
||||
|
||||
def preferred_languages_array
|
||||
return @preferred_languages_array if defined?(@preferred_languages_array)
|
||||
|
||||
|
|
|
|||
|
|
@ -1,24 +0,0 @@
|
|||
require "rails_helper"
|
||||
|
||||
RSpec.describe ReadingList, type: :labor do
|
||||
let(:user) { create(:user) }
|
||||
let(:article) { create(:article) }
|
||||
let(:article2) { create(:article) }
|
||||
let(:article3) { create(:article) }
|
||||
|
||||
def create_reaction(user, article)
|
||||
Reaction.create!(
|
||||
user_id: user.id,
|
||||
reactable_id: article.id,
|
||||
reactable_type: "Article",
|
||||
category: "readinglist",
|
||||
)
|
||||
end
|
||||
|
||||
it "returns cached ids of articles that have been reacted to" do
|
||||
create_reaction(user, article)
|
||||
create_reaction(user, article2)
|
||||
|
||||
expect(described_class.new(user).cached_ids_of_articles).to eq([article2.id, article.id])
|
||||
end
|
||||
end
|
||||
|
|
@ -1057,6 +1057,15 @@ RSpec.describe User, type: :model do
|
|||
user.follow(org)
|
||||
expect(user.reload.following_orgs_count).to eq(1)
|
||||
end
|
||||
|
||||
it "returns cached ids of articles that have been saved to their readinglist" do
|
||||
article = create(:article)
|
||||
article2 = create(:article)
|
||||
create(:reading_reaction, user: user, reactable: article)
|
||||
create(:reading_reaction, user: user, reactable: article2)
|
||||
|
||||
expect(user.cached_reading_list_article_ids).to eq([article2.id, article.id])
|
||||
end
|
||||
end
|
||||
|
||||
describe "#org_admin?" do
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue