Class: TopicTrackingStateSerializer

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

Instance Method Summary collapse

Methods inherited from ApplicationSerializer

expire_cache_fragment!, fragment_cache

Methods inherited from ActiveModel::Serializer

#include!

Instance Method Details

#dataObject



6
7
8
9
10
11
12
13
14
# File 'app/serializers/topic_tracking_state_serializer.rb', line 6

def data
  serializer = TopicTrackingStateItemSerializer.new(nil, scope: scope, root: false)
  # note we may have 1000 rows, avoiding serializer instansitation saves significant time
  # for 1000 rows this takes it down from 10ms to 3ms on a reasonably fast machine
  object.map do |item|
    serializer.object = item
    serializer.as_json
  end
end

#metaObject



16
17
18
19
20
21
22
23
24
25
26
# File 'app/serializers/topic_tracking_state_serializer.rb', line 16

def meta
  MessageBus.last_ids(
    TopicTrackingState::LATEST_MESSAGE_BUS_CHANNEL,
    TopicTrackingState::RECOVER_MESSAGE_BUS_CHANNEL,
    TopicTrackingState::DELETE_MESSAGE_BUS_CHANNEL,
    TopicTrackingState::DESTROY_MESSAGE_BUS_CHANNEL,
    TopicTrackingState::NEW_MESSAGE_BUS_CHANNEL,
    TopicTrackingState::UNREAD_MESSAGE_BUS_CHANNEL,
    TopicTrackingState.unread_channel_key(scope.user.id),
  )
end