refactor: Prevent reduce calls

This commit is contained in:
Joachim Van Herwegen
2023-10-30 16:53:38 +01:00
parent 990184dbb5
commit 20d4a0c3af
12 changed files with 84 additions and 75 deletions

View File

@@ -526,7 +526,11 @@ export class WrappedIndexedStorage<T extends IndexTypeCollection<T>> implements
indexResults.push(rootIds);
}
return indexResults.reduce((acc, ids): string[] => acc.filter((id): boolean => ids.includes(id)));
let indexedRoots: string[] = indexResults[0];
for (const ids of indexResults.slice(1)) {
indexedRoots = indexedRoots.filter((id): boolean => ids.includes(id));
}
return indexedRoots;
}
/**
@@ -581,9 +585,13 @@ export class WrappedIndexedStorage<T extends IndexTypeCollection<T>> implements
}
// For all keys that were not handled recursively: make sure that it matches the found objects
const remainingKeys = Object.keys(query).filter((key): boolean =>
key !== relation?.child.key || typeof query[key] === 'string');
return remainingKeys.reduce((acc, key): any[] => acc.filter((obj): boolean => obj[key] === query[key]), objs);
const remainingKeys = Object.keys(query).filter(
(key): boolean => key !== relation?.child.key || typeof query[key] === 'string',
);
for (const key of remainingKeys) {
objs = objs.filter((obj): boolean => obj[key] === query[key]);
}
return objs;
}
// --------------------------------- INDEX HELPERS ---------------------------------