From 9cff6c04eeb2df285a6aa352c076141465d6af49 Mon Sep 17 00:00:00 2001 From: Shivam Mishra Date: Thu, 4 May 2023 12:48:30 +0530 Subject: [PATCH] feat: preload label list --- app/models/concerns/labelable.rb | 11 +++++++++++ .../partials/_conversation.json.jbuilder | 4 ++-- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/app/models/concerns/labelable.rb b/app/models/concerns/labelable.rb index 5a71fe84f..a7b73e2d3 100644 --- a/app/models/concerns/labelable.rb +++ b/app/models/concerns/labelable.rb @@ -13,4 +13,15 @@ module Labelable new_labels << labels update!(label_list: new_labels) end + + def preloaded_label_list + unless @taggings_cache + @taggings_cache = [] + taggings.each do |tagging| + @taggings_cache << tagging.tag.name + end + end + + @taggings_cache || [] + end end diff --git a/app/views/api/v1/conversations/partials/_conversation.json.jbuilder b/app/views/api/v1/conversations/partials/_conversation.json.jbuilder index 15cae0b07..28de0df0a 100644 --- a/app/views/api/v1/conversations/partials/_conversation.json.jbuilder +++ b/app/views/api/v1/conversations/partials/_conversation.json.jbuilder @@ -33,7 +33,7 @@ json.can_reply conversation.can_reply? json.contact_last_seen_at conversation.contact_last_seen_at.to_i json.custom_attributes conversation.custom_attributes json.inbox_id conversation.inbox_id -json.labels conversation.label_list +json.labels conversation.preloaded_label_list json.muted conversation.muted? json.snoozed_until conversation.snoozed_until json.status conversation.status @@ -42,4 +42,4 @@ json.timestamp conversation.last_activity_at.to_i json.first_reply_created_at conversation.first_reply_created_at.to_i json.unread_count conversation.unread_incoming_messages.count json.last_non_activity_message conversation.messages.non_activity_messages.first.try(:push_event_data) -json.priority conversation.priority +json.priority conversation.priority \ No newline at end of file