UBERF-9724: Use updated accounts (#8452)

Signed-off-by: Andrey Sobolev <haiodo@gmail.com>
This commit is contained in:
Andrey Sobolev
2025-04-14 09:36:20 +07:00
committed by GitHub
parent 143f0bc7b6
commit 5ca2a73fba
28 changed files with 1506 additions and 1153 deletions
@@ -14,6 +14,7 @@ import core, {
TxCUD,
TxProcessor,
TxUpdateDoc,
systemAccount,
systemAccountUuid,
type Class,
type TxMixin
@@ -176,50 +177,45 @@ async function updateDocSyncInfo (
cache: Map<string, any>,
toApply: Tx[]
): Promise<void> {
// TODO: FIXME
// throw new Error('Not implemented')
// const checkTx = (tx: Tx): boolean =>
// control.hierarchy.isDerived(tx._class, core.class.TxCUD) &&
// (tx as TxCUD<Doc>).objectClass === github.class.DocSyncInfo &&
// (tx as TxCUD<Doc>).objectId === cud.objectId
// const txes = [...control.txes, ...control.ctx.contextData.broadcast.txes, ...toApply]
// // Check already captured Txes
// for (const i of txes) {
// if (checkTx(i)) {
// // We have sync doc create request already.
// return
// }
// }
// const [account] = control.modelDb.findAllSync(contact.class.PersonAccount, {
// _id: tx.modifiedBy as PersonId
// })
// // Do not modify state if is modified by github service.
// if (account === undefined) {
// return
// }
// const projects =
// (cache.get('projects') as GithubProject[]) ??
// (await control.queryFind(control.ctx, github.mixin.GithubProject, {}, { projection: { _id: 1 } }))
// cache.set('projects', projects)
// if (projects.some((it) => it._id === (space as Ref<GithubProject>))) {
// const sdoc =
// (cache.get(cud.objectId) as DocSyncInfo) ??
// (
// await control.findAll(control.ctx, github.class.DocSyncInfo, {
// _id: cud.objectId as Ref<DocSyncInfo>
// })
// ).shift()
// // We need to check if sync doc is already exists.
// if (sdoc === undefined) {
// // Created by non github integration
// // We need to create the doc sync info
// createSyncDoc(control, cud, tx, space, toApply)
// } else {
// cache.set(cud.objectId, sdoc)
// // We need to create the doc sync info
// updateSyncDoc(control, cud, space, sdoc, toApply)
// }
// }
const checkTx = (tx: Tx): boolean =>
control.hierarchy.isDerived(tx._class, core.class.TxCUD) &&
(tx as TxCUD<Doc>).objectClass === github.class.DocSyncInfo &&
(tx as TxCUD<Doc>).objectId === cud.objectId
const txes = [...control.txes, ...control.ctx.contextData.broadcast.txes, ...toApply]
// Check already captured Txes
for (const i of txes) {
if (checkTx(i)) {
// We have sync doc create request already.
return
}
}
// Do not modify state if is modified by github service.
if (tx.modifiedBy === systemAccount.primarySocialId) {
return
}
const projects =
(cache.get('projects') as GithubProject[]) ??
(await control.queryFind(control.ctx, github.mixin.GithubProject, {}, { projection: { _id: 1 } }))
cache.set('projects', projects)
if (projects.some((it) => it._id === (space as Ref<GithubProject>))) {
const sdoc =
(cache.get(cud.objectId) as DocSyncInfo) ??
(
await control.findAll(control.ctx, github.class.DocSyncInfo, {
_id: cud.objectId as Ref<DocSyncInfo>
})
).shift()
// We need to check if sync doc is already exists.
if (sdoc === undefined) {
// Created by non github integration
// We need to create the doc sync info
createSyncDoc(control, cud, tx, space, toApply)
} else {
cache.set(cud.objectId, sdoc)
// We need to create the doc sync info
updateSyncDoc(control, cud, space, sdoc, toApply)
}
}
}
function isDocSyncUpdateRequired (h: Hierarchy, coll: TxCUD<Doc>): boolean {