mirror of
https://github.com/hcengineering/platform.git
synced 2025-01-22 19:38:17 +00:00
UBERF-9093: Fix connection establish (#7623)
Some checks are pending
CI / build (push) Waiting to run
CI / svelte-check (push) Blocked by required conditions
CI / formatting (push) Blocked by required conditions
CI / test (push) Blocked by required conditions
CI / uitest (push) Waiting to run
CI / uitest-pg (push) Waiting to run
CI / uitest-qms (push) Waiting to run
CI / docker-build (push) Blocked by required conditions
CI / dist-build (push) Blocked by required conditions
Some checks are pending
CI / build (push) Waiting to run
CI / svelte-check (push) Blocked by required conditions
CI / formatting (push) Blocked by required conditions
CI / test (push) Blocked by required conditions
CI / uitest (push) Waiting to run
CI / uitest-pg (push) Waiting to run
CI / uitest-qms (push) Waiting to run
CI / docker-build (push) Blocked by required conditions
CI / dist-build (push) Blocked by required conditions
This commit is contained in:
parent
65e037cc7e
commit
be10f68c15
@ -254,9 +254,20 @@ export async function createClient (
|
||||
}
|
||||
}
|
||||
}
|
||||
let initialized = false
|
||||
const conn = await ctx.with('connect', {}, () => connect(txHandler))
|
||||
|
||||
const { mode, current, addition } = await ctx.with('load-model', {}, (ctx) => loadModel(ctx, conn, txPersistence))
|
||||
switch (mode) {
|
||||
case 'same':
|
||||
case 'upgrade':
|
||||
await ctx.with('build-model', {}, (ctx) => buildModel(ctx, current, modelFilter, hierarchy, model))
|
||||
break
|
||||
case 'addition':
|
||||
await ctx.with('build-model', {}, (ctx) =>
|
||||
buildModel(ctx, current.concat(addition), modelFilter, hierarchy, model)
|
||||
)
|
||||
}
|
||||
|
||||
txBuffer = txBuffer.filter((tx) => tx.space !== core.space.Model)
|
||||
|
||||
client = new ClientImpl(conn)
|
||||
@ -268,70 +279,50 @@ export async function createClient (
|
||||
const oldOnConnect:
|
||||
| ((event: ClientConnectEvent, lastTx: string | undefined, data: any) => Promise<void>)
|
||||
| undefined = conn.onConnect
|
||||
|
||||
await new Promise<void>((resolve) => {
|
||||
conn.onConnect = async (event, _lastTx, data) => {
|
||||
console.log('Client: onConnect', event)
|
||||
if (event === ClientConnectEvent.Maintenance) {
|
||||
lastTx = _lastTx
|
||||
await oldOnConnect?.(ClientConnectEvent.Maintenance, _lastTx, data)
|
||||
return
|
||||
}
|
||||
// Find all new transactions and apply
|
||||
const { mode, current, addition } = await ctx.with('load-model', {}, (ctx) => loadModel(ctx, conn, txPersistence))
|
||||
if (!initialized) {
|
||||
switch (mode) {
|
||||
case 'same':
|
||||
case 'upgrade':
|
||||
await ctx.with('build-model', {}, (ctx) => buildModel(ctx, current, modelFilter, hierarchy, model))
|
||||
break
|
||||
case 'addition':
|
||||
await ctx.with('build-model', {}, (ctx) =>
|
||||
buildModel(ctx, current.concat(addition), modelFilter, hierarchy, model)
|
||||
)
|
||||
}
|
||||
initialized = true
|
||||
} else {
|
||||
switch (mode) {
|
||||
case 'upgrade':
|
||||
// We have upgrade procedure and need rebuild all stuff.
|
||||
hierarchy = new Hierarchy()
|
||||
model = new ModelDb(hierarchy)
|
||||
;(client as ClientImpl).setModel(hierarchy, model)
|
||||
|
||||
await ctx.with('build-model', {}, (ctx) => buildModel(ctx, current, modelFilter, hierarchy, model))
|
||||
await oldOnConnect?.(ClientConnectEvent.Upgraded, _lastTx, data)
|
||||
// No need to fetch more stuff since upgrade was happened.
|
||||
break
|
||||
case 'addition':
|
||||
await ctx.with('build-model', {}, (ctx) =>
|
||||
buildModel(ctx, current.concat(addition), modelFilter, hierarchy, model)
|
||||
)
|
||||
break
|
||||
}
|
||||
}
|
||||
resolve()
|
||||
|
||||
if (lastTx === undefined) {
|
||||
// No need to do anything here since we connected.
|
||||
await oldOnConnect?.(event, _lastTx, data)
|
||||
lastTx = _lastTx
|
||||
resolve()
|
||||
return
|
||||
}
|
||||
|
||||
if (lastTx === _lastTx) {
|
||||
// Same lastTx, no need to refresh
|
||||
await oldOnConnect?.(ClientConnectEvent.Reconnected, _lastTx, data)
|
||||
resolve()
|
||||
return
|
||||
}
|
||||
conn.onConnect = async (event, _lastTx, data) => {
|
||||
console.log('Client: onConnect', event)
|
||||
if (event === ClientConnectEvent.Maintenance) {
|
||||
lastTx = _lastTx
|
||||
// We need to trigger full refresh on queries, etc.
|
||||
await oldOnConnect?.(ClientConnectEvent.Refresh, lastTx, data)
|
||||
resolve()
|
||||
await oldOnConnect?.(ClientConnectEvent.Maintenance, _lastTx, data)
|
||||
return
|
||||
}
|
||||
})
|
||||
// Find all new transactions and apply
|
||||
const { mode, current, addition } = await ctx.with('load-model', {}, (ctx) => loadModel(ctx, conn, txPersistence))
|
||||
|
||||
switch (mode) {
|
||||
case 'upgrade':
|
||||
// We have upgrade procedure and need rebuild all stuff.
|
||||
hierarchy = new Hierarchy()
|
||||
model = new ModelDb(hierarchy)
|
||||
;(client as ClientImpl).setModel(hierarchy, model)
|
||||
|
||||
await ctx.with('build-model', {}, (ctx) => buildModel(ctx, current, modelFilter, hierarchy, model))
|
||||
await oldOnConnect?.(ClientConnectEvent.Upgraded, _lastTx, data)
|
||||
// No need to fetch more stuff since upgrade was happened.
|
||||
break
|
||||
case 'addition':
|
||||
await ctx.with('build-model', {}, (ctx) =>
|
||||
buildModel(ctx, current.concat(addition), modelFilter, hierarchy, model)
|
||||
)
|
||||
break
|
||||
}
|
||||
|
||||
if (lastTx === undefined) {
|
||||
// No need to do anything here since we connected.
|
||||
await oldOnConnect?.(event, _lastTx, data)
|
||||
lastTx = _lastTx
|
||||
return
|
||||
}
|
||||
|
||||
if (lastTx === _lastTx) {
|
||||
// Same lastTx, no need to refresh
|
||||
await oldOnConnect?.(ClientConnectEvent.Reconnected, _lastTx, data)
|
||||
return
|
||||
}
|
||||
lastTx = _lastTx
|
||||
// We need to trigger full refresh on queries, etc.
|
||||
await oldOnConnect?.(ClientConnectEvent.Refresh, lastTx, data)
|
||||
}
|
||||
|
||||
return client
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user