Skip to content

Commit

Permalink
#1452 - save of nested card results to cache.
Browse files Browse the repository at this point in the history
  • Loading branch information
petmongrels committed Jul 12, 2024
1 parent bb20f8d commit b6ccc08
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 16 deletions.
32 changes: 18 additions & 14 deletions packages/openchs-android/src/service/CustomDashboardCacheService.js
Original file line number Diff line number Diff line change
Expand Up @@ -129,18 +129,6 @@ class CustomDashboardCacheService extends BaseService {
this.saveOrUpdate(dashboardCache);
}

updateNestedCardResults(dashboardUUID, reportCard, results) {
const dashboardCache = getDashboardCache(this, dashboardUUID);
_.remove(dashboardCache.nestedReportCardResults, (x) => x.reportCard === reportCard.uuid && x.dashboard === dashboardCache.dashboard.uuid);
results.forEach(result => {
result.dashboard = dashboardCache.dashboard.uuid;
result.reportCard = reportCard.uuid;
dashboardCache.nestedReportCardResults.push(result);
});
dashboardCache.updatedAt = new Date();
this.saveOrUpdate(dashboardCache);
}

clearResults(dashboardUUID) {
const dashboardCache = getDashboardCache(this, dashboardUUID);
dashboardCache.reportCardResults = [];
Expand All @@ -156,19 +144,35 @@ class CustomDashboardCacheService extends BaseService {
});
}

updateReportCardResult(dashboardUUID, reportCard, reportCardResult) {
updateNestedCardResults(dashboardUUID, reportCard, results) {
const db = this.db;
db.write(() => {
let dashboardCache = this.findByFiltered("dashboard.uuid", dashboardUUID, CustomDashboardCache.schema.name);
results.forEach((nestedReportCardResult, index) => {
const matching = _.filter(dashboardCache.nestedReportCardResults, (x) => x.reportCard === reportCard.getCardId(index) && x.dashboard === dashboardCache.dashboard.uuid);
matching.forEach((x) => {
dashboardCache.nestedReportCardResults.pop(x);
});
nestedReportCardResult.dashboard = dashboardUUID;
nestedReportCardResult.reportCard = reportCard.getCardId(index);
dashboardCache.nestedReportCardResults.push(nestedReportCardResult);
});
dashboardCache.updatedAt = new Date();
});
}

updateReportCardResult(dashboardUUID, reportCard, reportCardResult) {
const db = this.db;
db.write(() => {
let dashboardCache = this.findByFiltered("dashboard.uuid", dashboardUUID, CustomDashboardCache.schema.name);
const matching = _.filter(dashboardCache.reportCardResults, (x) => x.reportCard === reportCard.uuid && x.dashboard === dashboardCache.dashboard.uuid);
matching.forEach((x) => {
dashboardCache.reportCardResults.pop(x);
});
reportCardResult.dashboard = dashboardUUID;
reportCardResult.reportCard = reportCard.uuid;
dashboardCache.reportCardResults.push(reportCardResult);
General.logDebugTemp("CustomDashboardCacheService", "Removed report card results", matching.length, dashboardCache.reportCardResults.length);
dashboardCache.updatedAt = new Date();
});
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -751,7 +751,7 @@ class RuleEvaluationService extends BaseService {
return queryResult.length !== undefined;
}

getDashboardCardCount(reportCard, ruleInput) {
getDashboardCardResult(reportCard, ruleInput) {
const queryResult = this.executeDashboardCardRule(reportCard, ruleInput);
if (!queryResult.hasErrorMsg && this.isOldStyleQueryResult(queryResult)) {
return ReportCardResult.create(queryResult.length, null, true);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ class ReportCardService extends BaseService {
const standardReportCardType = reportCard.standardReportCardType;
switch (true) {
case _.isNil(standardReportCardType) :
return this.getService(RuleEvaluationService).getDashboardCardCount(reportCard, reportFilters);
return this.getService(RuleEvaluationService).getDashboardCardResult(reportCard, reportFilters);
case standardReportCardType.isApprovalType() :
return this.getCountForApprovalCardsType(standardReportCardType, reportFilters);
case standardReportCardType.isDefaultType() :
Expand Down

0 comments on commit b6ccc08

Please sign in to comment.