Class: TopicSummarySerializer

Inherits:
ApplicationSerializer show all
Defined in:
app/serializers/topic_summary_serializer.rb

Instance Method Summary collapse

Methods inherited from ApplicationSerializer

expire_cache_fragment!, fragment_cache

Methods inherited from ActiveModel::Serializer

#include!

Instance Method Details

#can_regenerateObject



6
7
8
# File 'app/serializers/topic_summary_serializer.rb', line 6

def can_regenerate
  Summarization::Base.can_request_summary_for?(scope.current_user)
end

#new_posts_since_summaryObject



10
11
12
13
14
15
16
17
18
19
20
21
# File 'app/serializers/topic_summary_serializer.rb', line 10

def new_posts_since_summary
  # Postgres uses discrete range types for int4range, which means
  # (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

  object.target.highest_post_number.to_i - object.content_range&.max.to_i
end