From df82f2f30bc107e7fc535d29b812be787ae34dfc Mon Sep 17 00:00:00 2001 From: Shivam Mishra Date: Thu, 28 Nov 2024 23:18:24 +0530 Subject: [PATCH] feat: skip meta fetch if data is atleast 10s old --- .../dashboard/store/modules/conversationStats.js | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/app/javascript/dashboard/store/modules/conversationStats.js b/app/javascript/dashboard/store/modules/conversationStats.js index 201bf6564..de535c00d 100644 --- a/app/javascript/dashboard/store/modules/conversationStats.js +++ b/app/javascript/dashboard/store/modules/conversationStats.js @@ -5,6 +5,7 @@ const state = { mineCount: 0, unAssignedCount: 0, allCount: 0, + updatedOn: null, }; export const getters = { @@ -13,6 +14,14 @@ export const getters = { export const actions = { get: async ({ commit }, params) => { + const currentTime = new Date(); + const lastUpdatedTime = new Date(state.updatedOn); + + if (currentTime - lastUpdatedTime < 10000) { + console.warn('Skipping conversation meta fetch'); + return; + } + try { const response = await ConversationApi.meta(params); const { @@ -40,6 +49,7 @@ export const mutations = { $state.mineCount = mineCount; $state.allCount = allCount; $state.unAssignedCount = unAssignedCount; + $state.updatedOn = new Date(); }, };