Only generate summaries when there is enough activity
This commit is contained in:
@@ -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
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user