TSK-1086: Fix merge (#2961)

Signed-off-by: Andrey Sobolev <haiodo@gmail.com>
This commit is contained in:
Andrey Sobolev 2023-04-12 19:54:54 +07:00 committed by GitHub
parent 08621c4bc1
commit 341aa4dbfb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
9 changed files with 75 additions and 28 deletions

View File

@ -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<Doc>).objectClass === 'contact:class:EmployeeAccount'
)
}
atxes.forEach((tx) => (tx.modifiedBy === core.account.System && !isEmployeeAccount(tx) ? systemTx : userTx).push(tx))
if (allowedPlugins !== undefined) {
fillConfiguration(systemTx, configs)

View File

@ -234,7 +234,7 @@
<EmployeeBox
showNavigate={false}
label={contact.string.MergeEmployeeTo}
docQuery={{ active: true }}
docQuery={{ active: { $in: [true, false] } }}
bind:value={targetEmployee}
/>
<ChannelsDropdown

View File

@ -23,7 +23,7 @@
const notificationClient = NotificationClientImpl.getClient()
const lastViews = notificationClient.getLastViews()
$: lastView = ($lastViews as any)[value._id]
$: lastView = (($lastViews as any) ?? {})[value._id]
$: hasNotification = lastView !== undefined && lastView !== -1 && lastView < value.modifiedOn
</script>

View File

@ -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)
}
})

View File

@ -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)
}
}
}

View File

@ -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)

View File

@ -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<Doc>(this.metrics, c, { _class: c }, { projection: { _id: 1 } }))

View File

@ -101,7 +101,7 @@ export const contentStageId = 'cnt-v2b'
/**
* @public
*/
export const fieldStateId = 'fld-v2'
export const fieldStateId = 'fld-v3'
/**
* @public

View File

@ -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)],