From e4eaba35afe463b77e3431d6e5490df794af3882 Mon Sep 17 00:00:00 2001 From: Harman-singh-waraich Date: Mon, 6 May 2024 23:26:08 +0530 Subject: [PATCH] fix: handle-file-datasource-duplicate-cases --- schema.graphql | 2 +- src/GeneralizedTCRMapping.ts | 16 +++++++++++++--- src/LightGeneralizedTCRMapping.ts | 11 ++++++++--- src/fileHandlers/EvidenceMetadataHandler.ts | 6 +++++- src/fileHandlers/LEvidenceMetadataHandler.ts | 5 ++++- src/fileHandlers/LItemMetadataHandler.ts | 5 +++-- subgraph.template.yaml | 2 +- 7 files changed, 35 insertions(+), 12 deletions(-) diff --git a/schema.graphql b/schema.graphql index fcc170f..be17b96 100644 --- a/schema.graphql +++ b/schema.graphql @@ -156,7 +156,7 @@ type LItem @entity { } type LItemMetadata @entity { - "ipfs cid" + "ipfs cid - Litem ID" id: ID! "The parsed data describing the item." props: [ItemProp!]! @derivedFrom(field: "item") diff --git a/src/GeneralizedTCRMapping.ts b/src/GeneralizedTCRMapping.ts index 1ca9591..49e8a09 100644 --- a/src/GeneralizedTCRMapping.ts +++ b/src/GeneralizedTCRMapping.ts @@ -1,5 +1,11 @@ /* eslint-disable prefer-const */ -import { Bytes, BigInt, Address, log } from '@graphprotocol/graph-ts'; +import { + Bytes, + BigInt, + Address, + log, + DataSourceContext, +} from '@graphprotocol/graph-ts'; import { Item, Request, @@ -614,8 +620,12 @@ export function handleEvidence(event: EvidenceEvent): void { ); const ipfsHash = extractPath(event.params._evidence); - evidence.metadata = ipfsHash; - EvidenceMetadataTemplate.create(ipfsHash); + evidence.metadata = `${ipfsHash}-${evidence.id}`; + + const context = new DataSourceContext(); + context.setString('evidenceId', evidence.id); + + EvidenceMetadataTemplate.createWithContext(ipfsHash, context); evidenceGroup.save(); evidence.save(); diff --git a/src/LightGeneralizedTCRMapping.ts b/src/LightGeneralizedTCRMapping.ts index c7635f2..565cb8b 100644 --- a/src/LightGeneralizedTCRMapping.ts +++ b/src/LightGeneralizedTCRMapping.ts @@ -250,7 +250,9 @@ export function handleNewItem(event: NewItem): void { item.latestRequestSubmissionTime = BigInt.fromI32(0); const ipfsHash = extractPath(event.params._data); - item.metadata = ipfsHash; + item.metadata = `${ipfsHash}-${graphItemID}`; + + log.debug('Creating datasource for ipfs hash : {}', [ipfsHash]); const context = new DataSourceContext(); context.setString('graphItemID', graphItemID); @@ -850,8 +852,11 @@ export function handleEvidence(event: EvidenceEvent): void { ); const ipfsHash = extractPath(event.params._evidence); - evidence.metadata = ipfsHash; - EvidenceMetadataTemplate.create(ipfsHash); + evidence.metadata = `${ipfsHash}-${evidence.id}`; + + const context = new DataSourceContext(); + context.setString('evidenceId', evidence.id); + EvidenceMetadataTemplate.createWithContext(ipfsHash, context); evidenceGroup.save(); evidence.save(); diff --git a/src/fileHandlers/EvidenceMetadataHandler.ts b/src/fileHandlers/EvidenceMetadataHandler.ts index b214adb..f2e005b 100644 --- a/src/fileHandlers/EvidenceMetadataHandler.ts +++ b/src/fileHandlers/EvidenceMetadataHandler.ts @@ -3,7 +3,11 @@ import { EvidenceMetadata } from '../../generated/schema'; export function handleGTCREvidenceMetadata(content: Bytes): void { const id = dataSource.stringParam(); - const evidence = new EvidenceMetadata(id); + + const context = dataSource.context(); + const evidenceId = context.getString('evidenceId'); + + const evidence = new EvidenceMetadata(`${id}-${evidenceId}`); const value = json.fromBytes(content).toObject(); log.debug(`ipfs hash : {}, content : {}`, [id, content.toString()]); diff --git a/src/fileHandlers/LEvidenceMetadataHandler.ts b/src/fileHandlers/LEvidenceMetadataHandler.ts index 77ad980..c41e782 100644 --- a/src/fileHandlers/LEvidenceMetadataHandler.ts +++ b/src/fileHandlers/LEvidenceMetadataHandler.ts @@ -3,7 +3,10 @@ import { EvidenceMetadata } from '../../generated/schema'; export function handleLGTCREvidenceMetadata(content: Bytes): void { const id = dataSource.stringParam(); - const evidence = new EvidenceMetadata(id); + const context = dataSource.context(); + const evidenceId = context.getString('evidenceId'); + + const evidence = new EvidenceMetadata(`${id}-${evidenceId}`); const value = json.fromBytes(content).toObject(); log.debug(`ipfs hash : {}, content : {}`, [id, content.toString()]); diff --git a/src/fileHandlers/LItemMetadataHandler.ts b/src/fileHandlers/LItemMetadataHandler.ts index 449240f..be533e7 100644 --- a/src/fileHandlers/LItemMetadataHandler.ts +++ b/src/fileHandlers/LItemMetadataHandler.ts @@ -4,14 +4,15 @@ import { JSONValueToBool, JSONValueToMaybeString } from '../utils'; export function handleLItemMetadata(content: Bytes): void { const id = dataSource.stringParam(); - const metadata = new LItemMetadata(id); const value = json.fromBytes(content).toObject(); - const context = dataSource.context(); + const context = dataSource.context(); const graphItemID = context.getString('graphItemID'); const address = context.getString('address'); + const metadata = new LItemMetadata(`${id}-${graphItemID}`); + metadata.keywords = address; log.debug(`ipfs hash : {}, content : {}`, [id, content.toString()]); diff --git a/subgraph.template.yaml b/subgraph.template.yaml index a4ccbf2..d1572f7 100644 --- a/subgraph.template.yaml +++ b/subgraph.template.yaml @@ -1,4 +1,4 @@ -specVersion: 0.0.4 +specVersion: 1.0.0 description: Generalized TCR features: - fullTextSearch