From 32938dadd71b57cb60a70039e1fb018f97571ca9 Mon Sep 17 00:00:00 2001 From: Matt Jankowski Date: Tue, 26 Mar 2024 09:21:20 -0400 Subject: [PATCH] Add `not_allowed` scope for `PreviewCardTrend` (#29599) --- app/models/preview_card_trend.rb | 2 ++ app/models/trends/links.rb | 4 ++-- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/app/models/preview_card_trend.rb b/app/models/preview_card_trend.rb index da2ea2f8c..58155971a 100644 --- a/app/models/preview_card_trend.rb +++ b/app/models/preview_card_trend.rb @@ -15,5 +15,7 @@ class PreviewCardTrend < ApplicationRecord include RankedTrend belongs_to :preview_card + scope :allowed, -> { where(allowed: true) } + scope :not_allowed, -> { where(allowed: false) } end diff --git a/app/models/trends/links.rb b/app/models/trends/links.rb index 76e50aa7a..0650c4109 100644 --- a/app/models/trends/links.rb +++ b/app/models/trends/links.rb @@ -86,8 +86,8 @@ class Trends::Links < Trends::Base def request_review PreviewCardTrend.pluck('distinct language').flat_map do |language| - score_at_threshold = PreviewCardTrend.where(language: language, allowed: true).by_rank.ranked_below(options[:review_threshold]).first&.score || 0 - preview_card_trends = PreviewCardTrend.where(language: language, allowed: false).joins(:preview_card) + score_at_threshold = PreviewCardTrend.where(language: language).allowed.by_rank.ranked_below(options[:review_threshold]).first&.score || 0 + preview_card_trends = PreviewCardTrend.where(language: language).not_allowed.joins(:preview_card) preview_card_trends.filter_map do |trend| preview_card = trend.preview_card