mirror of
https://github.com/hcengineering/platform.git
synced 2025-06-04 23:04:47 +00:00
Merge remote-tracking branch 'origin/develop' into staging
Signed-off-by: Andrey Sobolev <haiodo@gmail.com>
This commit is contained in:
commit
e82f0efaaf
@ -254,9 +254,20 @@ export async function createClient (
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
let initialized = false
|
|
||||||
const conn = await ctx.with('connect', {}, () => connect(txHandler))
|
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)
|
txBuffer = txBuffer.filter((tx) => tx.space !== core.space.Model)
|
||||||
|
|
||||||
client = new ClientImpl(conn)
|
client = new ClientImpl(conn)
|
||||||
@ -268,8 +279,6 @@ export async function createClient (
|
|||||||
const oldOnConnect:
|
const oldOnConnect:
|
||||||
| ((event: ClientConnectEvent, lastTx: string | undefined, data: any) => Promise<void>)
|
| ((event: ClientConnectEvent, lastTx: string | undefined, data: any) => Promise<void>)
|
||||||
| undefined = conn.onConnect
|
| undefined = conn.onConnect
|
||||||
|
|
||||||
await new Promise<void>((resolve) => {
|
|
||||||
conn.onConnect = async (event, _lastTx, data) => {
|
conn.onConnect = async (event, _lastTx, data) => {
|
||||||
console.log('Client: onConnect', event)
|
console.log('Client: onConnect', event)
|
||||||
if (event === ClientConnectEvent.Maintenance) {
|
if (event === ClientConnectEvent.Maintenance) {
|
||||||
@ -279,19 +288,7 @@ export async function createClient (
|
|||||||
}
|
}
|
||||||
// Find all new transactions and apply
|
// Find all new transactions and apply
|
||||||
const { mode, current, addition } = await ctx.with('load-model', {}, (ctx) => loadModel(ctx, conn, txPersistence))
|
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) {
|
switch (mode) {
|
||||||
case 'upgrade':
|
case 'upgrade':
|
||||||
// We have upgrade procedure and need rebuild all stuff.
|
// We have upgrade procedure and need rebuild all stuff.
|
||||||
@ -309,29 +306,23 @@ export async function createClient (
|
|||||||
)
|
)
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
}
|
|
||||||
resolve()
|
|
||||||
|
|
||||||
if (lastTx === undefined) {
|
if (lastTx === undefined) {
|
||||||
// No need to do anything here since we connected.
|
// No need to do anything here since we connected.
|
||||||
await oldOnConnect?.(event, _lastTx, data)
|
await oldOnConnect?.(event, _lastTx, data)
|
||||||
lastTx = _lastTx
|
lastTx = _lastTx
|
||||||
resolve()
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if (lastTx === _lastTx) {
|
if (lastTx === _lastTx) {
|
||||||
// Same lastTx, no need to refresh
|
// Same lastTx, no need to refresh
|
||||||
await oldOnConnect?.(ClientConnectEvent.Reconnected, _lastTx, data)
|
await oldOnConnect?.(ClientConnectEvent.Reconnected, _lastTx, data)
|
||||||
resolve()
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
lastTx = _lastTx
|
lastTx = _lastTx
|
||||||
// We need to trigger full refresh on queries, etc.
|
// We need to trigger full refresh on queries, etc.
|
||||||
await oldOnConnect?.(ClientConnectEvent.Refresh, lastTx, data)
|
await oldOnConnect?.(ClientConnectEvent.Refresh, lastTx, data)
|
||||||
resolve()
|
|
||||||
}
|
}
|
||||||
})
|
|
||||||
|
|
||||||
return client
|
return client
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user