@utaba/deep-memory-storage-cosmosdb 0.9.0 → 0.9.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.cjs CHANGED
@@ -919,6 +919,7 @@ async function exploreNeighborhood(conn, repositoryId, entityId, options) {
919
919
  for (let depth = 0; depth < options.depth; depth++) {
920
920
  const layer = {};
921
921
  const nextFrontier = /* @__PURE__ */ new Set();
922
+ const layerCache = /* @__PURE__ */ new Map();
922
923
  for (const currentId of frontier) {
923
924
  const rels = await getRelationshipsForEntity(conn, repositoryId, currentId, options);
924
925
  for (const rel of rels) {
@@ -932,20 +933,20 @@ async function exploreNeighborhood(conn, repositoryId, entityId, options) {
932
933
  } else {
933
934
  connectedId = rel.sourceEntityId;
934
935
  }
935
- if (!visited.has(connectedId)) {
936
- if (options.entityTypes && options.entityTypes.length > 0) {
937
- const entity = await getEntityLight(conn, repositoryId, connectedId);
938
- if (!entity || !options.entityTypes.includes(entity.entityType)) continue;
939
- layer[relType].entities.push(entity);
936
+ if (visited.has(connectedId)) continue;
937
+ let entity = layerCache.get(connectedId);
938
+ if (entity === void 0) {
939
+ const loaded = await getEntityLight(conn, repositoryId, connectedId);
940
+ if (loaded && (!options.entityTypes || options.entityTypes.length === 0 || options.entityTypes.includes(loaded.entityType))) {
941
+ entity = loaded;
940
942
  } else {
941
- const entity = await getEntityLight(conn, repositoryId, connectedId);
942
- if (entity) {
943
- layer[relType].entities.push(entity);
944
- }
943
+ entity = null;
945
944
  }
946
- visited.add(connectedId);
947
- nextFrontier.add(connectedId);
945
+ layerCache.set(connectedId, entity);
946
+ if (entity) nextFrontier.add(connectedId);
948
947
  }
948
+ if (!entity) continue;
949
+ layer[relType].entities.push(entity);
949
950
  layer[relType].relationships.push(rel);
950
951
  layer[relType].total = layer[relType].entities.length;
951
952
  }
@@ -960,6 +961,9 @@ async function exploreNeighborhood(conn, repositoryId, entityId, options) {
960
961
  if (Object.keys(layer).length > 0) {
961
962
  layers.push(layer);
962
963
  }
964
+ for (const id of nextFrontier) {
965
+ visited.add(id);
966
+ }
963
967
  frontier = nextFrontier;
964
968
  if (frontier.size === 0) break;
965
969
  }