From dff3ccd4a4fff958b63d4278035097842fda1f9d Mon Sep 17 00:00:00 2001 From: Denis Bykhov Date: Mon, 27 May 2024 14:38:46 +0500 Subject: [PATCH] Query fixes (#5660) Signed-off-by: Denis Bykhov --- packages/query/src/index.ts | 13 +++++++++++-- server/core/src/fulltext.ts | 5 +---- 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/packages/query/src/index.ts b/packages/query/src/index.ts index 1dd035c27e..ee5c46c920 100644 --- a/packages/query/src/index.ts +++ b/packages/query/src/index.ts @@ -1296,12 +1296,12 @@ export class LiveQuery implements WithTx, Client { // We need to add trigger once more, since elastic could have a huge lag with document availability. if (trigger || this.triggerCounter > 0) { if (trigger) { - this.triggerCounter = 5 // Schedule 5 refreshes on every 5 seconds. + this.triggerCounter = 2 // Schedule 2 refreshes on every 10 seconds. } setTimeout(() => { this.triggerCounter-- void this.checkUpdateEvents(evt, false) - }, 5000) + }, 10000) } const h = this.client.getHierarchy() @@ -1319,6 +1319,15 @@ export class LiveQuery implements WithTx, Client { Analytics.handleError(err) console.error(err) } + } else { + const queries = this.queries.get(q._class) + const pos = queries?.indexOf(q) ?? -1 + if (pos >= 0 && queries !== undefined) { + queries.splice(pos, 1) + if (queries?.length === 0) { + this.queries.delete(q._class) + } + } } } } diff --git a/server/core/src/fulltext.ts b/server/core/src/fulltext.ts index df609a153f..82a1ba2a33 100644 --- a/server/core/src/fulltext.ts +++ b/server/core/src/fulltext.ts @@ -248,16 +248,13 @@ export class FullTextIndex implements WithFind { // Just assign scores based on idex result.forEach((it) => { const idDoc = indexedDocMap.get(it._id) - const { _score, id, _class, ...extra } = idDoc as any + const { _score } = idDoc as any it.$source = { - ...extra, $score: _score } }) if (scoreSearch !== undefined) { result.sort((a, b) => scoreSearch * ((a.$source?.$score ?? 0) - (b.$source?.$score ?? 0))) - } - if (scoreSearch !== undefined) { if (options?.limit !== undefined && options?.limit < result.length) { result = toFindResult(result.slice(0, options?.limit), result.total) }