diff --git a/packages/integration-sdk-runtime/src/storage/FileSystemGraphObjectStore/FileSystemGraphObjectStore.ts b/packages/integration-sdk-runtime/src/storage/FileSystemGraphObjectStore/FileSystemGraphObjectStore.ts index d8f81902..d404fd1a 100644 --- a/packages/integration-sdk-runtime/src/storage/FileSystemGraphObjectStore/FileSystemGraphObjectStore.ts +++ b/packages/integration-sdk-runtime/src/storage/FileSystemGraphObjectStore/FileSystemGraphObjectStore.ts @@ -211,11 +211,24 @@ export class FileSystemGraphObjectStore implements GraphObjectStore { filter: GraphObjectFilter, iteratee: GraphObjectIteratee, ) { - 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(); + 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); + }, }); } @@ -223,11 +236,24 @@ export class FileSystemGraphObjectStore implements GraphObjectStore { filter: GraphObjectFilter, iteratee: GraphObjectIteratee, ) { - 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(); + 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); + }, }); }