Skip to content
This repository has been archived by the owner on Mar 14, 2024. It is now read-only.

Detecting Report Changes: further improvements and cleanup #25

Merged
merged 3 commits into from
Feb 19, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/domain/report-data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ export class ReportData {
asHash(): string {
return crypto
.createHash('sha256')
.update(JSON.stringify(this))
.update(JSON.stringify(this.data))
sleidig marked this conversation as resolved.
Show resolved Hide resolved
.digest('hex');
}
}
29 changes: 22 additions & 7 deletions src/report-changes/core/report-changes.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -107,16 +107,21 @@ export class ReportChangesService {
continue;
}

const reportChangeEventObservable =
this.calculateNewReportData(changeDetector);
const reportChangeEventObservable = this.calculateNewReportData(
changeDetector,
docChange,
);

affectedReports.push(reportChangeEventObservable);
}

return zip(affectedReports);
}

private calculateNewReportData(changeDetector: ReportChangeDetector) {
private calculateNewReportData(
changeDetector: ReportChangeDetector,
docChange: DocChangeDetails,
) {
return this.createReportCalculation
.startReportCalculation(changeDetector.report)
.pipe(
Expand All @@ -132,11 +137,21 @@ export class ReportChangesService {
new Reference(outcome.result.id),
);
}),
filter(
(calcUpdate) =>
filter((calcUpdate) => {
if (
(calcUpdate.outcome as ReportCalculationOutcomeSuccess)
?.result_hash !== changeDetector.lastCalculationHash,
),
?.result_hash !== changeDetector.lastCalculationHash
) {
return true;
} else {
console.log(
'Report calculation did not change from doc',
changeDetector.report,
docChange,
);
return false;
}
}),
tap(
(calcUpdate) =>
(changeDetector.lastCalculationHash = (
Expand Down
Loading