From e33649a7723f3cdb5c576923023d7b66e35f01af Mon Sep 17 00:00:00 2001 From: chiragsalian Date: Thu, 31 Aug 2023 17:22:35 -0700 Subject: [PATCH 01/10] getByActionID --- lib/ReportHistoryStore.jsx | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/lib/ReportHistoryStore.jsx b/lib/ReportHistoryStore.jsx index 3e1a0455..429f4552 100644 --- a/lib/ReportHistoryStore.jsx +++ b/lib/ReportHistoryStore.jsx @@ -167,6 +167,42 @@ export default class ReportHistoryStore { return promise; } + /** + * Gets the history by reportActionID. + * + * @param {Number} reportID + * @param {Boolean} ignoreCache + * + * @returns {Deferred} + */ + getByActionID(reportID, ignoreCache) { + const promise = new Deferred(); + + // Remove the cache entry if we're ignoring the cache, since we'll be replacing it later. + if (ignoreCache) { + delete this.cache[reportID]; + } + + // We'll poll the API for the un-cached history + const cachedHistory = this.cache[reportID] || []; + const lastHistoryItem = _.last(cachedHistory) || {}; + + this.API.Report_GetHistory({ + reportID, + reportActionID: lastHistoryItem.reportActionID || 0 + }) + .done((recentHistory) => { + // Update history with new items fetched + this.mergeItemsByTimestamp(reportID, recentHistory); + + // Return history for this report + promise.resolve(this.cache[reportID]); + }) + .fail(promise.reject); + + return promise; + } + /** * Gets the history from the cache if it exists. Otherwise fully loads the history. * From 72a7b04132dd0b69fa50631c48d24981849c0760 Mon Sep 17 00:00:00 2001 From: chiragsalian Date: Thu, 31 Aug 2023 17:23:05 -0700 Subject: [PATCH 02/10] adding reportActionsLimit --- lib/ReportHistoryStore.jsx | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/lib/ReportHistoryStore.jsx b/lib/ReportHistoryStore.jsx index 429f4552..f80b94e6 100644 --- a/lib/ReportHistoryStore.jsx +++ b/lib/ReportHistoryStore.jsx @@ -172,10 +172,11 @@ export default class ReportHistoryStore { * * @param {Number} reportID * @param {Boolean} ignoreCache + * @param [Number] reportActionsLimit * * @returns {Deferred} */ - getByActionID(reportID, ignoreCache) { + getByActionID(reportID, ignoreCache, reportActionsLimit) { const promise = new Deferred(); // Remove the cache entry if we're ignoring the cache, since we'll be replacing it later. @@ -189,7 +190,8 @@ export default class ReportHistoryStore { this.API.Report_GetHistory({ reportID, - reportActionID: lastHistoryItem.reportActionID || 0 + reportActionID: lastHistoryItem.reportActionID || 0, + reportActionsLimit, }) .done((recentHistory) => { // Update history with new items fetched From e1ecd026e9268c2e4c1c60cfe5720cc8a07e91f4 Mon Sep 17 00:00:00 2001 From: chiragsalian Date: Thu, 31 Aug 2023 17:24:07 -0700 Subject: [PATCH 03/10] mergeHistoryByTimestamp --- lib/ReportHistoryStore.jsx | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/lib/ReportHistoryStore.jsx b/lib/ReportHistoryStore.jsx index f80b94e6..a991cedb 100644 --- a/lib/ReportHistoryStore.jsx +++ b/lib/ReportHistoryStore.jsx @@ -130,6 +130,28 @@ export default class ReportHistoryStore { this.cache[reportID] = _.sortBy(newCache, 'sequenceNumber').reverse(); } + /** + * Merges history items into the cache and creates it if it doesn't yet exist. + * + * @param {Number} reportID + * @param {Object[]} newHistory + */ + mergeHistoryByTimestamp(reportID, newHistory) { + if (newHistory.length === 0) { + return; + } + + const newCache = _.reduce(newHistory.reverse(), (prev, curr) => { + if (!_.findWhere(prev, {reportActionTimestamp: curr.reportActionTimestamp})) { + prev.unshift(curr); + } + return prev; + }, this.cache[reportID] || []); + + // Sort items in case they have become out of sync + this.cache[reportID] = _.sortBy(newCache, 'reportActionTimestamp'); + } + /** * Gets the history. * @@ -195,7 +217,7 @@ export default class ReportHistoryStore { }) .done((recentHistory) => { // Update history with new items fetched - this.mergeItemsByTimestamp(reportID, recentHistory); + this.mergeHistoryByTimestamp(reportID, recentHistory); // Return history for this report promise.resolve(this.cache[reportID]); From 7017d063ff8095a5bdd6545ea9d578074970ea1a Mon Sep 17 00:00:00 2001 From: chiragsalian Date: Thu, 31 Aug 2023 17:24:35 -0700 Subject: [PATCH 04/10] insertIntoCacheByActionID --- lib/ReportHistoryStore.jsx | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/lib/ReportHistoryStore.jsx b/lib/ReportHistoryStore.jsx index a991cedb..989f8ecc 100644 --- a/lib/ReportHistoryStore.jsx +++ b/lib/ReportHistoryStore.jsx @@ -92,6 +92,38 @@ export default class ReportHistoryStore { return promise; }, + /** + * Set a history item directly into the cache. Checks to see if we have the previous item first. + * + * @param {Number} reportID + * @param {Object} reportAction + * + * @returns {Deferred} + */ + insertIntoCacheByActionID: (reportID, reportAction) => { + const promise = new Deferred(); + this.getFromCache(reportID) + .done((cachedHistory) => { + + // Do we have the reportAction immediately before this one? + if (_.some(cachedHistory, ({reportActionID}) => reportActionID === reportAction.reportActionID)) { + // If we have the previous one then we can assume we have an up to date history minus the most recent + // and must merge it into the cache + this.mergeItems(reportID, [reportAction]); + return promise.resolve(this.filterHiddenActions(this.cache[reportID])); + } + + // If we get here we have an incomplete history and should get + // the report history again, but this time do not check the cache first. + this.get(reportID) + .done(reportHistory => promise.resolve(this.filterHiddenActions(reportHistory))) + .fail(promise.reject); + }) + .fail(promise.reject); + + return promise; + }, + /** * Certain events need to completely clear the cache. This method allows other code modules using this * (like Web, Mobile) to assign which events would do so. From 11949b7b6e90ba86846c61b35b8afda9172a044b Mon Sep 17 00:00:00 2001 From: chiragsalian Date: Tue, 5 Sep 2023 16:14:03 -0700 Subject: [PATCH 05/10] improvements --- lib/ReportHistoryStore.jsx | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/lib/ReportHistoryStore.jsx b/lib/ReportHistoryStore.jsx index 989f8ecc..28f782c2 100644 --- a/lib/ReportHistoryStore.jsx +++ b/lib/ReportHistoryStore.jsx @@ -56,6 +56,25 @@ export default class ReportHistoryStore { return promise; }, + /** + * Returns the history for a given report. + * Note that we are unable to ask for the cached history. + * + * @param {Number} reportID + * @param {Boolean} ignoreCache - useful if you need to force the report history to reload completely. + * + * @returns {Deferred} + */ + getByActionID: (reportID, ignoreCache = false) => { + const promise = new Deferred(); + this.getByActionID(reportID, ignoreCache) + .done((reportHistory) => { + promise.resolve(this.filterHiddenActions(reportHistory)); + }) + .fail(promise.reject); + return promise; + }, + /** * Set a history item directly into the cache. Checks to see if we have the previous item first. * @@ -104,7 +123,6 @@ export default class ReportHistoryStore { const promise = new Deferred(); this.getFromCache(reportID) .done((cachedHistory) => { - // Do we have the reportAction immediately before this one? if (_.some(cachedHistory, ({reportActionID}) => reportActionID === reportAction.reportActionID)) { // If we have the previous one then we can assume we have an up to date history minus the most recent @@ -181,7 +199,7 @@ export default class ReportHistoryStore { }, this.cache[reportID] || []); // Sort items in case they have become out of sync - this.cache[reportID] = _.sortBy(newCache, 'reportActionTimestamp'); + this.cache[reportID] = _.sortBy(newCache, 'reportActionTimestamp').reverse(); } /** From 32ac959d59d588751c286fad2b0cf94d8b40201e Mon Sep 17 00:00:00 2001 From: chiragsalian Date: Fri, 20 Oct 2023 14:06:24 -0700 Subject: [PATCH 06/10] getFromCacheByActionID --- lib/ReportHistoryStore.jsx | 31 ++++++++++++++++++++++++++++--- 1 file changed, 28 insertions(+), 3 deletions(-) diff --git a/lib/ReportHistoryStore.jsx b/lib/ReportHistoryStore.jsx index 28f782c2..263ef7c8 100644 --- a/lib/ReportHistoryStore.jsx +++ b/lib/ReportHistoryStore.jsx @@ -121,19 +121,19 @@ export default class ReportHistoryStore { */ insertIntoCacheByActionID: (reportID, reportAction) => { const promise = new Deferred(); - this.getFromCache(reportID) + this.getFromCacheByActionID(reportID) .done((cachedHistory) => { // Do we have the reportAction immediately before this one? if (_.some(cachedHistory, ({reportActionID}) => reportActionID === reportAction.reportActionID)) { // If we have the previous one then we can assume we have an up to date history minus the most recent // and must merge it into the cache - this.mergeItems(reportID, [reportAction]); + this.mergeHistoryByTimestamp(reportID, [reportAction]); return promise.resolve(this.filterHiddenActions(this.cache[reportID])); } // If we get here we have an incomplete history and should get // the report history again, but this time do not check the cache first. - this.get(reportID) + this.getByActionID(reportID) .done(reportHistory => promise.resolve(this.filterHiddenActions(reportHistory))) .fail(promise.reject); }) @@ -301,4 +301,29 @@ export default class ReportHistoryStore { return promise.resolve(cachedHistory); } + + /** + * Gets the history from the cache if it exists. Otherwise fully loads the history. + * + * @param {Number} reportID + * + * @return {Deferrred} + */ + getFromCacheByActionID(reportID) { + const promise = new Deferred(); + const cachedHistory = this.cache[reportID] || []; + + // First check to see if we even have this history in cache + if (_.isEmpty(cachedHistory)) { + this.API.Report_GetHistory({reportID}) + .done((reportHistory) => { + this.mergeHistoryByTimestamp(reportID, reportHistory); + promise.resolve(this.cache[reportID]); + }) + .fail(promise.reject); + return promise; + } + + return promise.resolve(cachedHistory); + } } From 4662f28129e2ad2e6e736ce2d309a4ecd9839eae Mon Sep 17 00:00:00 2001 From: chiragsalian Date: Mon, 23 Oct 2023 16:52:19 -0700 Subject: [PATCH 07/10] removing unused reportActionsLimit --- lib/ReportHistoryStore.jsx | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/lib/ReportHistoryStore.jsx b/lib/ReportHistoryStore.jsx index 263ef7c8..c9d663e6 100644 --- a/lib/ReportHistoryStore.jsx +++ b/lib/ReportHistoryStore.jsx @@ -244,11 +244,10 @@ export default class ReportHistoryStore { * * @param {Number} reportID * @param {Boolean} ignoreCache - * @param [Number] reportActionsLimit * * @returns {Deferred} */ - getByActionID(reportID, ignoreCache, reportActionsLimit) { + getByActionID(reportID, ignoreCache) { const promise = new Deferred(); // Remove the cache entry if we're ignoring the cache, since we'll be replacing it later. @@ -263,7 +262,6 @@ export default class ReportHistoryStore { this.API.Report_GetHistory({ reportID, reportActionID: lastHistoryItem.reportActionID || 0, - reportActionsLimit, }) .done((recentHistory) => { // Update history with new items fetched From 2757cbe7a4657ab68c5cac92e413b829439a77d2 Mon Sep 17 00:00:00 2001 From: chiragsalian Date: Tue, 24 Oct 2023 11:35:31 -0700 Subject: [PATCH 08/10] DRY code --- lib/ReportHistoryStore.jsx | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/lib/ReportHistoryStore.jsx b/lib/ReportHistoryStore.jsx index c9d663e6..99bcf8b0 100644 --- a/lib/ReportHistoryStore.jsx +++ b/lib/ReportHistoryStore.jsx @@ -311,15 +311,9 @@ export default class ReportHistoryStore { const promise = new Deferred(); const cachedHistory = this.cache[reportID] || []; - // First check to see if we even have this history in cache + // If comment is not in cache then fetch it if (_.isEmpty(cachedHistory)) { - this.API.Report_GetHistory({reportID}) - .done((reportHistory) => { - this.mergeHistoryByTimestamp(reportID, reportHistory); - promise.resolve(this.cache[reportID]); - }) - .fail(promise.reject); - return promise; + return this.getByActionID(reportID); } return promise.resolve(cachedHistory); From 671b20d66f27fb95cbebf4dc644e568c57e5acaa Mon Sep 17 00:00:00 2001 From: chiragsalian Date: Tue, 24 Oct 2023 11:57:04 -0700 Subject: [PATCH 09/10] renaming to getFlatHistory and removing older getFromCache --- lib/ReportHistoryStore.jsx | 39 ++++++-------------------------------- 1 file changed, 6 insertions(+), 33 deletions(-) diff --git a/lib/ReportHistoryStore.jsx b/lib/ReportHistoryStore.jsx index 99bcf8b0..ff9a7534 100644 --- a/lib/ReportHistoryStore.jsx +++ b/lib/ReportHistoryStore.jsx @@ -65,9 +65,9 @@ export default class ReportHistoryStore { * * @returns {Deferred} */ - getByActionID: (reportID, ignoreCache = false) => { + getFlatHistory: (reportID, ignoreCache = false) => { const promise = new Deferred(); - this.getByActionID(reportID, ignoreCache) + this.getFlatHistory(reportID, ignoreCache) .done((reportHistory) => { promise.resolve(this.filterHiddenActions(reportHistory)); }) @@ -121,7 +121,7 @@ export default class ReportHistoryStore { */ insertIntoCacheByActionID: (reportID, reportAction) => { const promise = new Deferred(); - this.getFromCacheByActionID(reportID) + this.getFromCache(reportID) .done((cachedHistory) => { // Do we have the reportAction immediately before this one? if (_.some(cachedHistory, ({reportActionID}) => reportActionID === reportAction.reportActionID)) { @@ -240,14 +240,14 @@ export default class ReportHistoryStore { } /** - * Gets the history by reportActionID. + * Gets the history. This flow does not depend on the deprecated sequence number in report actions. * * @param {Number} reportID * @param {Boolean} ignoreCache * * @returns {Deferred} */ - getByActionID(reportID, ignoreCache) { + getFlatHistory(reportID, ignoreCache) { const promise = new Deferred(); // Remove the cache entry if we're ignoring the cache, since we'll be replacing it later. @@ -257,11 +257,9 @@ export default class ReportHistoryStore { // We'll poll the API for the un-cached history const cachedHistory = this.cache[reportID] || []; - const lastHistoryItem = _.last(cachedHistory) || {}; this.API.Report_GetHistory({ reportID, - reportActionID: lastHistoryItem.reportActionID || 0, }) .done((recentHistory) => { // Update history with new items fetched @@ -286,34 +284,9 @@ export default class ReportHistoryStore { const promise = new Deferred(); const cachedHistory = this.cache[reportID] || []; - // First check to see if we even have this history in cache - if (_.isEmpty(cachedHistory)) { - this.API.Report_GetHistory({reportID}) - .done((reportHistory) => { - this.mergeItems(reportID, reportHistory); - promise.resolve(this.cache[reportID]); - }) - .fail(promise.reject); - return promise; - } - - return promise.resolve(cachedHistory); - } - - /** - * Gets the history from the cache if it exists. Otherwise fully loads the history. - * - * @param {Number} reportID - * - * @return {Deferrred} - */ - getFromCacheByActionID(reportID) { - const promise = new Deferred(); - const cachedHistory = this.cache[reportID] || []; - // If comment is not in cache then fetch it if (_.isEmpty(cachedHistory)) { - return this.getByActionID(reportID); + return this.getFlatHistory(reportID); } return promise.resolve(cachedHistory); From c82aa199dafd82a02ab236697257277c0d110d76 Mon Sep 17 00:00:00 2001 From: chiragsalian Date: Tue, 24 Oct 2023 12:37:34 -0700 Subject: [PATCH 10/10] renaming to getFlatHistory --- lib/ReportHistoryStore.jsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/ReportHistoryStore.jsx b/lib/ReportHistoryStore.jsx index ff9a7534..5dddcec2 100644 --- a/lib/ReportHistoryStore.jsx +++ b/lib/ReportHistoryStore.jsx @@ -133,7 +133,7 @@ export default class ReportHistoryStore { // If we get here we have an incomplete history and should get // the report history again, but this time do not check the cache first. - this.getByActionID(reportID) + this.getFlatHistory(reportID) .done(reportHistory => promise.resolve(this.filterHiddenActions(reportHistory))) .fail(promise.reject); })