Skip to content

Commit

Permalink
Merge pull request #1092 from JupiterOne/fix-iterate-graphObjects
Browse files Browse the repository at this point in the history
Fix iterate graph objects
  • Loading branch information
Gonzalo-Avalos-Ribas authored Jul 2, 2024
2 parents 7481898 + 3768e3a commit 5afd53b
Showing 1 changed file with 30 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -211,23 +211,49 @@ export class FileSystemGraphObjectStore implements GraphObjectStore {
filter: GraphObjectFilter,
iteratee: GraphObjectIteratee<T>,
) {
await this.localGraphObjectStore.iterateEntities(filter, iteratee);
//TODO: Remove maps. This is a hack we did to avoid returning duplicated entities.
//This should not work this way.
//There is a detailed description of the changes to come to avoid having to do this
//Here: https://jupiterone.atlassian.net/wiki/spaces/INT/pages/786169857/Task+SDK+decouple+tasks
const iteratedEntities = new Map<string, boolean>();
await this.localGraphObjectStore.iterateEntities(filter, (obj: T) => {
iteratedEntities.set(obj._key, true);
return iteratee(obj);
});

await iterateEntityTypeIndex({
type: filter._type,
iteratee,
iteratee: (obj: T) => {
if (iteratedEntities.has(obj._key)) {
return;
}
return iteratee(obj);
},
});
}

async iterateRelationships<T extends Relationship = Relationship>(
filter: GraphObjectFilter,
iteratee: GraphObjectIteratee<T>,
) {
await this.localGraphObjectStore.iterateRelationships(filter, iteratee);
//TODO: Remove maps. This is a hack we did to avoid returning duplicated relationships.
//This should not work this way.
//There is a detailed description of the changes to come to avoid having to do this
//Here: https://jupiterone.atlassian.net/wiki/spaces/INT/pages/786169857/Task+SDK+decouple+tasks
const iteratedRelationships = new Map<string, boolean>();
await this.localGraphObjectStore.iterateRelationships(filter, (obj: T) => {
iteratedRelationships.set(obj._key, true);
return iteratee(obj);
});

await iterateRelationshipTypeIndex({
type: filter._type,
iteratee,
iteratee: (obj: T) => {
if (iteratedRelationships.has(obj._key)) {
return;
}
return iteratee(obj);
},
});
}

Expand Down

0 comments on commit 5afd53b

Please sign in to comment.