From 3994a7ec94800665282cf6078a00b0d541b2348e Mon Sep 17 00:00:00 2001 From: Denis Bykhov <80476319+BykhovDenis@users.noreply.github.com> Date: Sat, 2 Jul 2022 08:01:33 +0600 Subject: [PATCH] LQ fix (#2187) --- packages/query/src/index.ts | 27 +++++++++++++-------------- server/core/src/storage.ts | 2 ++ 2 files changed, 15 insertions(+), 14 deletions(-) diff --git a/packages/query/src/index.ts b/packages/query/src/index.ts index 7317fb73e6..12e8b92872 100644 --- a/packages/query/src/index.ts +++ b/packages/query/src/index.ts @@ -353,20 +353,7 @@ export class LiveQuery extends TxProcessor implements Client { } } else { const updatedDoc = q.result[pos] - if (updatedDoc.modifiedOn > tx.modifiedOn) return - if (updatedDoc.modifiedOn === tx.modifiedOn) { - const current = await this.findOne(q._class, { _id: updatedDoc._id }, q.options) - if (current !== undefined && this.match(q, current)) { - q.result[pos] = current - } else { - if (q.options?.limit === q.result.length) { - return await this.refresh(q) - } else { - q.result.splice(pos, 1) - q.total-- - } - } - } else { + if (updatedDoc.modifiedOn < tx.modifiedOn) { await this.__updateDoc(q, updatedDoc, tx) if (!this.match(q, updatedDoc)) { if (q.options?.limit === q.result.length) { @@ -378,6 +365,18 @@ export class LiveQuery extends TxProcessor implements Client { } else { q.result[pos] = updatedDoc } + } else { + const current = await this.findOne(q._class, { _id: updatedDoc._id }, q.options) + if (current !== undefined && this.match(q, current)) { + q.result[pos] = current + } else { + if (q.options?.limit === q.result.length) { + return await this.refresh(q) + } else { + q.result.splice(pos, 1) + q.total-- + } + } } } this.sort(q, tx) diff --git a/server/core/src/storage.ts b/server/core/src/storage.ts index afb0b978d2..ff5ce44567 100644 --- a/server/core/src/storage.ts +++ b/server/core/src/storage.ts @@ -446,6 +446,8 @@ class TServerStorage implements ServerStorage { )) ] + derived.sort((a, b) => a.modifiedOn - b.modifiedOn) + for (const tx of derived) { await ctx.with('derived-route-tx', { _class: txClass(tx) }, (ctx) => this.routeTx(ctx, tx)) }