Only generate summaries when there is enough activity

This commit is contained in:
Jorge Manrubia
2025-09-02 16:32:30 +02:00
parent d785f9f80f
commit c412ae89e6
2 changed files with 6 additions and 4 deletions
+2 -2
View File
@@ -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
+4 -2
View File
@@ -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