Change tx notify logic (#5172)

Signed-off-by: Denis Bykhov <bykhov.denis@gmail.com>
This commit is contained in:
Denis Bykhov 2024-04-04 11:02:17 +05:00 committed by GitHub
parent 20cd262081
commit 5d6c33249d
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 12 additions and 13 deletions

View File

@ -156,7 +156,6 @@ class ClientImpl implements AccountClient, BackupClient, MeasureClient {
// We need to handle it on server, before performing local live query updates.
const result = await this.conn.tx(tx)
this.notify?.(tx)
return result
}
@ -166,9 +165,14 @@ class ClientImpl implements AccountClient, BackupClient, MeasureClient {
async updateFromRemote (...tx: Tx[]): Promise<void> {
for (const t of tx) {
if (t.objectSpace === core.space.Model) {
this.hierarchy.tx(t)
await this.model.tx(t)
try {
if (t.objectSpace === core.space.Model) {
this.hierarchy.tx(t)
await this.model.tx(t)
}
} catch (err) {
console.error('failed to apply model transaction, skipping', t)
continue
}
}
this.notify?.(...tx)

View File

@ -76,7 +76,7 @@ FulltextStorage & {
}
await Promise.all([model.tx(tx), transactions.tx(tx)])
// Not required, since handled in client.
// handler(tx)
handler(tx)
return {}
},
close: async () => {},

View File

@ -156,7 +156,7 @@ export class ClientSession implements Session {
}
if (tx._class !== core.class.TxApplyIf) {
this.broadcast(this, this.token.workspace, { result: tx }, target)
this.broadcast(null, this.token.workspace, { result: tx }, target)
}
if (shouldBroadcast) {
if (this.useBroadcast) {
@ -176,7 +176,7 @@ export class ClientSession implements Session {
if (tx._class === core.class.TxApplyIf) {
;(result as TxApplyResult).derived.push(bevent)
}
this.broadcast(this, this.token.workspace, { result: bevent }, target)
this.broadcast(null, this.token.workspace, { result: bevent }, target)
} else {
if (tx._class === core.class.TxApplyIf) {
;(result as TxApplyResult).derived.push(...derived)
@ -184,12 +184,7 @@ export class ClientSession implements Session {
while (derived.length > 0) {
const part = derived.splice(0, 250)
console.log('Broadcasting part', part.length, derived.length)
this.broadcast(
tx._class === core.class.TxApplyIf ? this : null,
this.token.workspace,
{ result: part },
target
)
this.broadcast(null, this.token.workspace, { result: part }, target)
}
}
} else {