From 341aa4dbfb2b8bfcb18c696a6aaee1072f58080c Mon Sep 17 00:00:00 2001 From: Andrey Sobolev Date: Wed, 12 Apr 2023 19:54:54 +0700 Subject: [PATCH] TSK-1086: Fix merge (#2961) Signed-off-by: Andrey Sobolev --- packages/core/src/client.ts | 14 +++- .../src/components/MergeEmployee.svelte | 2 +- .../components/NotificationPresenter.svelte | 2 +- .../src/components/TableBrowser.svelte | 2 +- server-plugins/contact-resources/src/index.ts | 64 +++++++++++++------ server/core/src/fulltext.ts | 12 ++++ server/core/src/indexer/indexer.ts | 1 - server/core/src/indexer/types.ts | 2 +- server/core/src/processor/index.ts | 4 +- 9 files changed, 75 insertions(+), 28 deletions(-) diff --git a/packages/core/src/client.ts b/packages/core/src/client.ts index 37ca37d4fe..d48576d85f 100644 --- a/packages/core/src/client.ts +++ b/packages/core/src/client.ts @@ -21,7 +21,7 @@ import { Hierarchy } from './hierarchy' import { ModelDb } from './memdb' import type { DocumentQuery, FindOptions, FindResult, Storage, TxResult, WithLookup } from './storage' import { SortingOrder } from './storage' -import { Tx, TxCreateDoc, TxProcessor, TxUpdateDoc } from './tx' +import { Tx, TxCUD, TxCreateDoc, TxProcessor, TxUpdateDoc } from './tx' import { toFindResult } from './utils' const transactionThreshold = 500 @@ -233,7 +233,17 @@ async function loadModel ( const userTx: Tx[] = [] console.log('find' + (processedTx.size === 0 ? 'full model' : 'model diff'), atxes.length, Date.now() - t) - atxes.forEach((tx) => (tx.modifiedBy === core.account.System ? systemTx : userTx).push(tx)) + // Ignore Employee accounts. + function isEmployeeAccount (tx: Tx): boolean { + return ( + (tx._class === core.class.TxCreateDoc || + tx._class === core.class.TxUpdateDoc || + tx._class === core.class.TxRemoveDoc) && + (tx as TxCUD).objectClass === 'contact:class:EmployeeAccount' + ) + } + + atxes.forEach((tx) => (tx.modifiedBy === core.account.System && !isEmployeeAccount(tx) ? systemTx : userTx).push(tx)) if (allowedPlugins !== undefined) { fillConfiguration(systemTx, configs) diff --git a/plugins/contact-resources/src/components/MergeEmployee.svelte b/plugins/contact-resources/src/components/MergeEmployee.svelte index 33cb434138..ac2295da82 100644 --- a/plugins/contact-resources/src/components/MergeEmployee.svelte +++ b/plugins/contact-resources/src/components/MergeEmployee.svelte @@ -234,7 +234,7 @@ diff --git a/plugins/view-resources/src/components/TableBrowser.svelte b/plugins/view-resources/src/components/TableBrowser.svelte index cd54a9dfd5..28f08d261a 100644 --- a/plugins/view-resources/src/components/TableBrowser.svelte +++ b/plugins/view-resources/src/components/TableBrowser.svelte @@ -40,7 +40,7 @@ const listProvider = new ListSelectionProvider((offset: 1 | -1 | 0, of?: Doc, dir?: SelectDirection) => { if (dir === 'vertical') { // Select next - table.select(offset, of) + table?.select(offset, of) } }) diff --git a/server-plugins/contact-resources/src/index.ts b/server-plugins/contact-resources/src/index.ts index 9e7c4381dc..a3065203fe 100644 --- a/server-plugins/contact-resources/src/index.ts +++ b/server-plugins/contact-resources/src/index.ts @@ -134,13 +134,18 @@ async function updateAllRefs ( const descendants = control.hierarchy.getDescendants(attr.attributeOf) for (const d of descendants) { if (control.hierarchy.findDomain(d) !== undefined) { - const values = await control.findAll(d, { [attr.name]: sourceAccount.employee }) + while (true) { + const values = await control.findAll(d, { [attr.name]: sourceAccount.employee }, { limit: 100 }) + if (values.length === 0) { + break + } - const builder = new TxBuilder(control.hierarchy, control.modelDb, modifiedBy) - for (const v of values) { - await updateAttribute(builder, v, d, { key: attr.name, attr }, targetAccount.employee, targetAccount._id) + const builder = new TxBuilder(control.hierarchy, control.modelDb, modifiedBy) + for (const v of values) { + await updateAttribute(builder, v, d, { key: attr.name, attr }, targetAccount.employee, targetAccount._id) + } + await control.apply(builder.txes, true, true) } - await control.apply(builder.txes, true, true) } } } @@ -152,12 +157,17 @@ async function updateAllRefs ( const descendants = control.hierarchy.getDescendants(attr.attributeOf) for (const d of descendants) { if (control.hierarchy.findDomain(d) !== undefined) { - const values = await control.findAll(d, { [attr.name]: sourceAccount._id }) - const builder = new TxBuilder(control.hierarchy, control.modelDb, modifiedBy) - for (const v of values) { - await updateAttribute(builder, v, d, { key: attr.name, attr }, targetAccount._id, targetAccount._id) + while (true) { + const values = await control.findAll(d, { [attr.name]: sourceAccount._id }, { limit: 100 }) + if (values.length === 0) { + break + } + const builder = new TxBuilder(control.hierarchy, control.modelDb, modifiedBy) + for (const v of values) { + await updateAttribute(builder, v, d, { key: attr.name, attr }, targetAccount._id, targetAccount._id) + } + await control.apply(builder.txes, true, true) } - await control.apply(builder.txes, true, true) } } } @@ -172,12 +182,21 @@ async function updateAllRefs ( const descendants = control.hierarchy.getDescendants(attr.attributeOf) for (const d of descendants) { if (control.hierarchy.findDomain(d) !== undefined) { - const values = await control.findAll(attr.attributeOf, { [attr.name]: sourceAccount.employee }) - const builder = new TxBuilder(control.hierarchy, control.modelDb, modifiedBy) - for (const v of values) { - await updateAttribute(builder, v, d, { key: attr.name, attr }, targetAccount.employee, targetAccount._id) + while (true) { + const values = await control.findAll( + attr.attributeOf, + { [attr.name]: sourceAccount.employee }, + { limit: 100 } + ) + if (values.length === 0) { + break + } + const builder = new TxBuilder(control.hierarchy, control.modelDb, modifiedBy) + for (const v of values) { + await updateAttribute(builder, v, d, { key: attr.name, attr }, targetAccount.employee, targetAccount._id) + } + await control.apply(builder.txes, true, true) } - await control.apply(builder.txes, true, true) } } } @@ -189,12 +208,17 @@ async function updateAllRefs ( const descendants = control.hierarchy.getDescendants(attr.attributeOf) for (const d of descendants) { if (control.hierarchy.findDomain(d) !== undefined) { - const values = await control.findAll(d, { [attr.name]: sourceAccount._id }) - const builder = new TxBuilder(control.hierarchy, control.modelDb, modifiedBy) - for (const v of values) { - await updateAttribute(builder, v, d, { key: attr.name, attr }, targetAccount._id, targetAccount._id) + while (true) { + const values = await control.findAll(d, { [attr.name]: sourceAccount._id }, { limit: 100 }) + if (values.length === 0) { + break + } + const builder = new TxBuilder(control.hierarchy, control.modelDb, modifiedBy) + for (const v of values) { + await updateAttribute(builder, v, d, { key: attr.name, attr }, targetAccount._id, targetAccount._id) + } + await control.apply(builder.txes, true, true) } - await control.apply(builder.txes, true, true) } } } diff --git a/server/core/src/fulltext.ts b/server/core/src/fulltext.ts index 5fc280edad..10f6ab40d9 100644 --- a/server/core/src/fulltext.ts +++ b/server/core/src/fulltext.ts @@ -154,6 +154,18 @@ export class FullTextIndex implements WithFind { classes = classes.filter((it, idx, arr) => arr.indexOf(it) === idx) + classes = classes.filter((it) => { + if (typeof query._class === 'object') { + if (query._class?.$in !== undefined) { + return query._class.$in.includes(it) + } + if (query._class?.$nin !== undefined) { + return !query._class.$nin.includes(it) + } + } + return true + }) + const fullTextLimit = options?.limit ?? 200 let { docs, pass } = await this.indexer.search(classes, findQuery, fullTextLimit) diff --git a/server/core/src/indexer/indexer.ts b/server/core/src/indexer/indexer.ts index bf582184af..9a4745dd38 100644 --- a/server/core/src/indexer/indexer.ts +++ b/server/core/src/indexer/indexer.ts @@ -520,7 +520,6 @@ export class FullTextIndexPipeline implements FullTextPipeline { } catch (err: any) { console.error(err) } - console.log('Updated state for: ', c, newDocs.length) } const statesSet = new Set(states) const docIds = (await dbStorage.findAll(this.metrics, c, { _class: c }, { projection: { _id: 1 } })) diff --git a/server/core/src/indexer/types.ts b/server/core/src/indexer/types.ts index d8b776bf01..9245b3947b 100644 --- a/server/core/src/indexer/types.ts +++ b/server/core/src/indexer/types.ts @@ -101,7 +101,7 @@ export const contentStageId = 'cnt-v2b' /** * @public */ -export const fieldStateId = 'fld-v2' +export const fieldStateId = 'fld-v3' /** * @public diff --git a/server/core/src/processor/index.ts b/server/core/src/processor/index.ts index 2a3631ab75..9acc702fb6 100644 --- a/server/core/src/processor/index.ts +++ b/server/core/src/processor/index.ts @@ -116,7 +116,9 @@ export class AsyncTriggerProcessor { for (const f of this.functions) { result.push(...(await f(doc.tx, this.control))) } - } catch (err: any) {} + } catch (err: any) { + console.error(err) + } await this.storage.apply( this.metrics, [this.factory.createTxRemoveDoc(doc._class, doc.space, doc._id)],