From fc940e11f7cb9099ac2806b2932a6a856cc9c1e1 Mon Sep 17 00:00:00 2001 From: davelopez <46503462+davelopez@users.noreply.github.com> Date: Tue, 26 Jul 2022 13:57:14 +0200 Subject: [PATCH] Optimize history watcher for detailed contents This will requests the detailed view only for those items that are currently expanded in the history panel instead of all of them. --- .../store/historyStore/model/watchHistory.js | 25 +++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-) diff --git a/client/src/store/historyStore/model/watchHistory.js b/client/src/store/historyStore/model/watchHistory.js index 0a988168fca..372b3773b35 100644 --- a/client/src/store/historyStore/model/watchHistory.js +++ b/client/src/store/historyStore/model/watchHistory.js @@ -7,6 +7,7 @@ import defaultStore from "store/index"; import { urlData } from "utils/url"; +import { loadSet } from "utils/setCache"; import { getCurrentHistoryFromServer } from "./queries"; import { getGalaxyInstance } from "app"; @@ -52,12 +53,16 @@ export async function watchHistoryOnce(store) { lastUpdateTime = history.update_time; // execute request to obtain recently changed items const params = { + v: "dev", limit: limit, q: "update_time-ge", qv: lastRequestDate.toISOString(), - v: "dev", - view: "detailed", }; + // request detailed info only for the expanded datasets + const detailedIds = getCurrentlyExpandedHistoryContentIds(); + if (detailedIds.length) { + params["details"] = detailedIds.join(","); + } const url = `api/histories/${historyId}/contents`; lastRequestDate = new Date(); const payload = await urlData({ url, params }); @@ -104,3 +109,19 @@ export function rewatchHistory() { watchHistory(); } } + +/** + * Returns the set of history item IDs that are currently expanded in the history panel from the cache. + * These content items need to retrieve detailed information when updated. + * @returns {Array} List of history item IDs that are currently expanded. + */ +function getCurrentlyExpandedHistoryContentIds() { + const expandedItemIds = []; + const cacheKey = "expanded-history-items"; + const expandedItems = loadSet(cacheKey); + expandedItems.forEach((key) => { + // Items have the format: - + expandedItemIds.push(key.split("-")[1]); + }); + return expandedItemIds; +}