From c412ae89e6556fdb1c4b7d7f5d30775a017ecfa5 Mon Sep 17 00:00:00 2001 From: Jorge Manrubia Date: Tue, 2 Sep 2025 16:32:30 +0200 Subject: [PATCH] Only generate summaries when there is enough activity --- app/models/period_highlights.rb | 4 ++-- app/models/period_highlights/period.rb | 6 ++++-- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/app/models/period_highlights.rb b/app/models/period_highlights.rb index bb9302210..38d7ba0ff 100644 --- a/app/models/period_highlights.rb +++ b/app/models/period_highlights.rb @@ -6,14 +6,14 @@ class PeriodHighlights < ApplicationRecord def for(collections, starts_at:, duration: 1.week) period = Period.new(collections, starts_at:, duration:) - find_by(**period.as_params) if period.has_activity? + find_by(**period.as_params) if period.has_enough_activity? end private def create_for(collections, starts_at:, duration: 1.week) period = Period.new(collections, starts_at:, duration:) - if period.has_activity? + if period.has_enough_activity? summarizer = Event::Summarizer.new(period.events) summarized_content = summarizer.summarized_content # outside of transaction as this can be slow diff --git a/app/models/period_highlights/period.rb b/app/models/period_highlights/period.rb index 37c58370d..9aa8a41f6 100644 --- a/app/models/period_highlights/period.rb +++ b/app/models/period_highlights/period.rb @@ -1,4 +1,6 @@ class PeriodHighlights::Period + MIN_EVENTS_TO_BE_INTERESTING = 7 + attr_reader :collections, :starts_at, :duration def initialize(collections, starts_at:, duration:) @@ -11,8 +13,8 @@ class PeriodHighlights::Period @events ||= Event.where(collection: collections).where(created_at: window) end - def has_activity? - events.any? + def has_enough_activity? + events.count >= MIN_EVENTS_TO_BE_INTERESTING end def key