Skip to content

Commit 5716355

Browse files
committed
Give PnpProblems an ID based on hash of its value & dedupe based on it
1 parent fa9d276 commit 5716355

File tree

3 files changed

+23
-4
lines changed

3 files changed

+23
-4
lines changed

src/components/periodic-report/events/periodic-report-uploaded.event.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,6 @@ export class PeriodicReportUploadedEvent {
1515
) {}
1616

1717
@Once() get pnpResult() {
18-
return new PnpProgressExtractionResult();
18+
return new PnpProgressExtractionResult(this.file.id);
1919
}
2020
}

src/components/pnp/extraction-result/extraction-result.dto.ts

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
import { Field, InterfaceType, ObjectType } from '@nestjs/graphql';
22
import { many, Many } from '@seedcompany/common';
33
import { stripIndent } from 'common-tags';
4-
import { EnumType, makeEnum } from '~/common';
4+
import * as uuid from 'uuid';
5+
import { EnumType, ID, IdField, makeEnum } from '~/common';
56
import { InlineMarkdownScalar } from '~/common/markdown.scalar';
67
import { Cell } from '~/common/xlsx.util';
78

@@ -13,6 +14,9 @@ export const PnpProblemSeverity = makeEnum({
1314

1415
@ObjectType()
1516
export class PnpProblem {
17+
@IdField()
18+
readonly id: ID;
19+
1620
@Field(() => PnpProblemSeverity)
1721
readonly severity: PnpProblemSeverity;
1822

@@ -38,17 +42,30 @@ export class PnpProblem {
3842

3943
@InterfaceType()
4044
export abstract class PnpExtractionResult {
45+
constructor(private readonly fileVersionId: ID<'FileVersion'>) {}
46+
4147
@Field(() => [PnpProblem])
4248
readonly problems: PnpProblem[] = [];
4349

4450
addProblem(
45-
problem: Omit<PnpProblem, 'groups' | 'source'> & {
51+
problem: Omit<PnpProblem, 'id' | 'groups' | 'source'> & {
52+
id?: string;
4653
groups?: Many<string>;
4754
source: Cell;
4855
},
4956
) {
57+
const id = (problem.id ??
58+
uuid.v5(
59+
[this.fileVersionId, problem.message, problem.source.fqn].join('\0'),
60+
ID_NS,
61+
)) as ID;
62+
63+
// Ignore dupes
64+
if (this.problems.some((p) => p.id === id)) return;
65+
5066
this.problems.push({
5167
...problem,
68+
id,
5269
groups: [problem.source.sheet.name, ...many(problem.groups ?? [])],
5370
source: problem.source.fqn,
5471
});
@@ -58,3 +75,5 @@ export abstract class PnpExtractionResult {
5875
export class PnpPlanningExtractionResult extends PnpExtractionResult {}
5976
@ObjectType({ implements: PnpExtractionResult })
6077
export class PnpProgressExtractionResult extends PnpExtractionResult {}
78+
79+
const ID_NS = 'bab2666a-a0f5-4168-977d-7ef6399503f9';

src/components/product/handlers/extract-products-from-pnp.handler.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ export class ExtractProductsFromPnpHandler
4040
);
4141
const pnp = this.files.asDownloadable(fv);
4242

43-
const result = new PnpPlanningExtractionResult();
43+
const result = new PnpPlanningExtractionResult(pnp.id);
4444

4545
const actionableProductRows = await this.syncer.parse({
4646
engagementId: engagement.id,

0 commit comments

Comments
 (0)