From 689156901b074f7fce95c437604e39d2364e9cc4 Mon Sep 17 00:00:00 2001 From: Paolo Insogna Date: Mon, 13 Mar 2023 15:28:18 +0100 Subject: [PATCH] feat: Add internal cache for Lyra. --- src/methods/create.ts | 1 + src/methods/search.ts | 12 +++++++++--- src/types.ts | 1 + 3 files changed, 11 insertions(+), 3 deletions(-) diff --git a/src/methods/create.ts b/src/methods/create.ts index 06cf8d385..86644f518 100644 --- a/src/methods/create.ts +++ b/src/methods/create.ts @@ -119,6 +119,7 @@ export async function create propertiesToSearchWithTypes[prop] === "string"); + let propertiesToSearch = lyra.caches["propertiesToSearch"] as string[]; + if (!propertiesToSearch) { + const propertiesToSearchWithTypes = await lyra.index.getSearchablePropertiesWithTypes(index); + + propertiesToSearch = await lyra.index.getSearchableProperties(index); + propertiesToSearch = propertiesToSearch.filter((prop: string) => propertiesToSearchWithTypes[prop] === "string"); + + lyra.caches["propertiesToSearch"] = propertiesToSearch; + } if (properties && properties !== "*") { for (const prop of properties) { diff --git a/src/types.ts b/src/types.ts index a7ac0b182..8156f17d7 100644 --- a/src/types.ts +++ b/src/types.ts @@ -337,6 +337,7 @@ export type Lyra; [kInsertions]: number | undefined; [kRemovals]: number | undefined; };