From 780f33436c14004b1d5acfa8b25cc0ea41586f29 Mon Sep 17 00:00:00 2001 From: Boubaker Khanfir Date: Thu, 18 Jul 2024 10:05:02 +0100 Subject: [PATCH] fix: Optimize Fetch calls using extensions - MEED-7288 --- .../achievementsExtensions/extensions.js | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/wallet-webapps/src/main/webapp/vue-app/achievementsExtensions/extensions.js b/wallet-webapps/src/main/webapp/vue-app/achievementsExtensions/extensions.js index 194b1eacb..ad8595aa6 100644 --- a/wallet-webapps/src/main/webapp/vue-app/achievementsExtensions/extensions.js +++ b/wallet-webapps/src/main/webapp/vue-app/achievementsExtensions/extensions.js @@ -21,14 +21,18 @@ import {getRewardReportPeriods} from './js/service'; export function init() { extensionRegistry.registerExtension('engagementCenterAchievements', 'achievements-extensions', { type: 'wallet', - rewardPeriods: [], - init(from, to) { - getRewardReportPeriods(from, to, 0, -1).then(period => { - this.rewardPeriods = period; - }); - }, + computedCanUpdateStatus: {}, canUpdateStatus(createdDate) { - return this.rewardPeriods.filter(rewardPeriod => this.isInPeriod(rewardPeriod, createdDate)).length === 0; + if (createdDate in this.computedCanUpdateStatus) { + return this.computedCanUpdateStatus[createdDate]; + } else { + this.computedCanUpdateStatus[createdDate] = getRewardReportPeriods(from, to, 0, -1) + .then(period => { + this.computedCanUpdateStatus[createdDate] = period.filter(rewardPeriod => this.isInPeriod(rewardPeriod, createdDate)).length === 0; + return this.computedCanUpdateStatus[createdDate]; + }); + return this.computedCanUpdateStatus[createdDate]; + } }, isInPeriod(period, timestamp) { return timestamp >= period?.startDateInSeconds && timestamp <= period?.endDateInSeconds;