From 23e208ad1d492e5ba2838081ccf15bbd93411e9e Mon Sep 17 00:00:00 2001 From: Jesse Tomchak Date: Fri, 22 Dec 2023 11:46:45 -0700 Subject: [PATCH] bulk channels --- app/lib/mammoth/channels.rb | 2 +- app/lib/mammoth/status_origin.rb | 10 ++++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/app/lib/mammoth/channels.rb b/app/lib/mammoth/channels.rb index 4f24137a4..16a83c4ee 100644 --- a/app/lib/mammoth/channels.rb +++ b/app/lib/mammoth/channels.rb @@ -28,7 +28,7 @@ def select_channels_with_statuses(channels, user) origin = Mammoth::StatusOrigin.instance channel_feed_manager = ChannelFeedManager.instance channels.flat_map do |channel| - channel_feed_manager.fetch_threshold_statuses(channel[:id]).each { |s| origin.add_channel(s, user, channel) } + origin.bulk_add_channel(channel_feed_manager.fetch_threshold_statuses(channel[:id]), user, channel) end end diff --git a/app/lib/mammoth/status_origin.rb b/app/lib/mammoth/status_origin.rb index 95fbe4fa3..1a91019b2 100644 --- a/app/lib/mammoth/status_origin.rb +++ b/app/lib/mammoth/status_origin.rb @@ -34,6 +34,15 @@ def add_channel(status, user, channel) add_reason(list_key, status[:id], reason) end + + def bulk_add_channel(statuses, user, channel) + reasons = statuses.map do |s| + list_key = key(user[:acct], s[:id]) + reason = channel_reason(s, channel) + return {key: list_key, id: s[:id], reason: reason} + end + bulk_reasons(reasons) + end # Add MammothPick and Reason to list def add_mammoth_pick(status, user) @@ -50,6 +59,7 @@ def bulk_add_mammoth_pick(statuses, user) reason = mammoth_pick_reason(s) return {key: list_key, id: s[:id], reason: reason} end + bulk_reasons(reasons) end def bulk_reasons(reasons)