Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
8 changes: 8 additions & 0 deletions pop-subgraph/src/education-hub.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import {
import {
EducationHubContract,
EducationModule,
EducationModuleMetadata,
ModuleCompletion,
ModuleUpdate,
HatPermission,
Expand Down Expand Up @@ -52,6 +53,13 @@ function createEducationModuleMetadataSource(contentHash: Bytes, moduleEntityId:

let ipfsCid = bytes32ToCid(contentHash);

// EducationModuleMetadata is immutable — skip if already indexed to prevent
// duplicate INSERT conflicts when the same CID triggers multiple times
let existing = EducationModuleMetadata.load(ipfsCid);
if (existing != null) {
return;
}

let context = new DataSourceContext();
context.setString("moduleEntityId", moduleEntityId);
context.setBigInt("timestamp", timestamp);
Expand Down
11 changes: 8 additions & 3 deletions pop-subgraph/src/org-registry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import {
OrgRegistryContract,
Organization,
OrgMetaUpdate,
OrgMetadata,
RegisteredContract,
SwitchableBeaconContract
} from "../generated/schema";
Expand Down Expand Up @@ -59,13 +60,17 @@ function createIpfsDataSource(metadataHash: Bytes, orgId: Bytes): void {
// Convert bytes32 sha256 digest to IPFS CIDv0 string
let ipfsCid = bytes32ToCid(metadataHash);

// Skip if metadata already indexed (prevents duplicate IPFS data sources
// which would cause INSERT conflicts for immutable OrgMetadataLink children)
let existing = OrgMetadata.load(ipfsCid);
if (existing != null) {
return;
}

// Create context to pass orgId to the IPFS handler
let context = new DataSourceContext();
context.setBytes("orgId", orgId);

// Create the file data source with context
// If IPFS is unavailable or slow, this will be retried automatically
// and won't block the main chain indexing
OrgMetadataTemplate.createWithContext(ipfsCid, context);
}

Expand Down
11 changes: 8 additions & 3 deletions pop-subgraph/src/participation-token.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import {
ParticipationTokenContract,
HatPermission,
TokenRequest,
TokenRequestMetadata,
TokenBalance
} from "../generated/schema";
import { getOrCreateRole, loadExistingUser } from "./utils";
Expand Down Expand Up @@ -218,10 +219,14 @@ export function handleRequested(event: RequestedEvent): void {
if (ipfsCid.length > 0) {
tokenRequest.metadata = ipfsCid;

let context = new DataSourceContext();
context.setBigInt("timestamp", event.block.timestamp);
// TokenRequestMetadata is immutable — skip if already indexed
let existingMeta = TokenRequestMetadata.load(ipfsCid);
if (existingMeta == null) {
let context = new DataSourceContext();
context.setBigInt("timestamp", event.block.timestamp);

TokenRequestMetadataTemplate.createWithContext(ipfsCid, context);
TokenRequestMetadataTemplate.createWithContext(ipfsCid, context);
}
}

tokenRequest.save();
Expand Down
11 changes: 8 additions & 3 deletions pop-subgraph/src/task-manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import {
ProjectCapChange,
BountyCapChange,
TaskMetadata,
TaskApplicationMetadata,
ProjectMetadata,
TaskRejection
} from "../generated/schema";
Expand Down Expand Up @@ -421,10 +422,14 @@ export function handleTaskApplicationSubmitted(event: TaskApplicationSubmitted):
let applicationCid = bytes32ToCid(event.params.applicationHash);
application.metadata = applicationCid;

let context = new DataSourceContext();
context.setBigInt("timestamp", event.block.timestamp);
// TaskApplicationMetadata is immutable — skip if already indexed
let existingAppMeta = TaskApplicationMetadata.load(applicationCid);
if (existingAppMeta == null) {
let context = new DataSourceContext();
context.setBigInt("timestamp", event.block.timestamp);

TaskApplicationMetadataTemplate.createWithContext(applicationCid, context);
TaskApplicationMetadataTemplate.createWithContext(applicationCid, context);
}
}

application.save();
Expand Down
12 changes: 8 additions & 4 deletions pop-subgraph/src/universal-account-registry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import {
import {
UniversalAccountRegistry,
Account,
AccountMetadata,
UsernameChange,
AccountDeletion,
BatchRegistration,
Expand Down Expand Up @@ -272,8 +273,11 @@ export function handleProfileMetadataUpdated(event: ProfileMetadataUpdatedEvent)
account.metadata = ipfsCid;
account.save();

// Create IPFS file data source to fetch and parse the metadata
let context = new DataSourceContext();
context.setBytes("userAddress", userAddress);
AccountMetadataTemplate.createWithContext(ipfsCid, context);
// Skip creating IPFS data source if metadata already indexed
let existingMeta = AccountMetadata.load(ipfsCid);
if (existingMeta == null) {
let context = new DataSourceContext();
context.setBytes("userAddress", userAddress);
AccountMetadataTemplate.createWithContext(ipfsCid, context);
}
}
Loading