From 016a2c58ba690f1ca49655aaa3cbb223716aba99 Mon Sep 17 00:00:00 2001 From: Denis Bykhov <80476319+BykhovDenis@users.noreply.github.com> Date: Fri, 24 Jun 2022 14:58:52 +0600 Subject: [PATCH] Refresh query over limit (#2142) Signed-off-by: Denis Bykhov <80476319+BykhovDenis@users.noreply.github.com> --- packages/query/src/index.ts | 24 ++++++++++++++++++------ 1 file changed, 18 insertions(+), 6 deletions(-) diff --git a/packages/query/src/index.ts b/packages/query/src/index.ts index d9eb8cc34e..311a7ac0ed 100644 --- a/packages/query/src/index.ts +++ b/packages/query/src/index.ts @@ -342,8 +342,12 @@ export class LiveQuery extends TxProcessor implements Client { if (q.query.$search != null && q.query.$search.length > 0) { const match = await this.findOne(q._class, { $search: q.query.$search, _id: tx.objectId }, q.options) if (match === undefined) { - q.result.splice(pos, 1) - q.total-- + if (q.options?.limit === q.result.length) { + return await this.refresh(q) + } else { + q.result.splice(pos, 1) + q.total-- + } } else { q.result[pos] = match } @@ -355,14 +359,22 @@ export class LiveQuery extends TxProcessor implements Client { if (current !== undefined) { q.result[pos] = current } else { - q.result.splice(pos, 1) - q.total-- + if (q.options?.limit === q.result.length) { + return await this.refresh(q) + } else { + q.result.splice(pos, 1) + q.total-- + } } } else { await this.__updateDoc(q, updatedDoc, tx) if (!this.match(q, updatedDoc)) { - q.result.splice(pos, 1) - q.total-- + if (q.options?.limit === q.result.length) { + return await this.refresh(q) + } else { + q.result.splice(pos, 1) + q.total-- + } } else { q.result[pos] = updatedDoc }