Skip to content

Commit

Permalink
TSK-1086: Fix merge (#2961)
Browse files Browse the repository at this point in the history
Signed-off-by: Andrey Sobolev <haiodo@gmail.com>
  • Loading branch information
haiodo authored Apr 12, 2023
1 parent 08621c4 commit 341aa4d
Show file tree
Hide file tree
Showing 9 changed files with 76 additions and 29 deletions.
14 changes: 12 additions & 2 deletions packages/core/src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@
<EmployeeBox
showNavigate={false}
label={contact.string.MergeEmployeeTo}
docQuery={{ active: true }}
docQuery={{ active: { $in: [true, false] } }}
bind:value={targetEmployee}
/>
<ChannelsDropdown
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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>

Expand Down
2 changes: 1 addition & 1 deletion plugins/view-resources/src/components/TableBrowser.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
})
Expand Down
66 changes: 45 additions & 21 deletions server-plugins/contact-resources/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 })

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(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)
}
await control.apply(builder.txes, true, true)
}
await control.apply(builder.txes, true, true)
}
}
}
Expand All @@ -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)
}
}
}
Expand All @@ -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)
}
}
}
Expand All @@ -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)
}
}
}
Expand Down
12 changes: 12 additions & 0 deletions server/core/src/fulltext.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
1 change: 0 additions & 1 deletion server/core/src/indexer/indexer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 } }))
Expand Down
2 changes: 1 addition & 1 deletion server/core/src/indexer/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ export const contentStageId = 'cnt-v2b'
/**
* @public
*/
export const fieldStateId = 'fld-v2'
export const fieldStateId = 'fld-v3'

/**
* @public
Expand Down
4 changes: 3 additions & 1 deletion server/core/src/processor/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)],
Expand Down

0 comments on commit 341aa4d

Please sign in to comment.