Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix iterate graph objects #1092

Merged
merged 3 commits into from
Jul 2, 2024
Merged
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
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