2023-08-11 14:08:49 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
class TopicSummarySerializer < ApplicationSerializer
|
|
|
|
attributes :summarized_text, :algorithm, :outdated, :can_regenerate, :new_posts_since_summary
|
|
|
|
|
|
|
|
def can_regenerate
|
|
|
|
Summarization::Base.can_request_summary_for?(scope.current_user)
|
|
|
|
end
|
|
|
|
|
|
|
|
def new_posts_since_summary
|
2023-08-15 13:16:06 -04:00
|
|
|
# Postgres uses discrete range types for int4range, which means
|
2023-08-15 14:03:42 -04:00
|
|
|
# (1..2) is stored as (1...3).
|
|
|
|
#
|
|
|
|
# We use Range#max to work around this, which in the case above always returns 2.
|
|
|
|
# Be careful with using Range#end here, it could lead to unexpected results as:
|
|
|
|
#
|
|
|
|
# (1..2).end => 2
|
|
|
|
# (1...3).end => 3
|
2023-08-15 13:16:06 -04:00
|
|
|
|
2023-08-15 14:03:42 -04:00
|
|
|
object.target.highest_post_number.to_i - object.content_range&.max.to_i
|
2023-08-11 14:08:49 -04:00
|
|
|
end
|
|
|
|
end
|