Skip to content

Commit

Permalink
Change tx notify logic (#5172)
Browse files Browse the repository at this point in the history
Signed-off-by: Denis Bykhov <[email protected]>
  • Loading branch information
BykhovDenis committed Apr 4, 2024
1 parent 20cd262 commit 5d6c332
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 13 deletions.
12 changes: 8 additions & 4 deletions packages/core/src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand All @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion packages/query/src/__tests__/connection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 () => {},
Expand Down
11 changes: 3 additions & 8 deletions server/ws/src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -176,20 +176,15 @@ 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)
}
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 {
Expand Down

0 comments on commit 5d6c332

Please sign in to comment.