mirror of
https://github.com/discourse/discourse.git
synced 2024-11-23 06:04:11 +08:00
49f0cc16ba
This corrects two issues: 1. We were double serializing topic tracking state (as_json calls were not cached) 2. We were inefficiently serializing items by instantiating extra objects
28 lines
922 B
Ruby
28 lines
922 B
Ruby
# frozen_string_literal: true
|
|
|
|
class TopicTrackingStateSerializer < ApplicationSerializer
|
|
attributes :data, :meta
|
|
|
|
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
|
|
|
|
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
|
|
end
|