fix(api): optimize preUpdateMany

This commit is contained in:
yassinedorbozgithub 2025-04-12 06:31:08 +01:00
parent 3813635ee0
commit 69a994f9e3

View File

@ -172,15 +172,18 @@ export class BlockRepository extends BaseRepository<
category: string,
ids: string[],
): Promise<void> {
for (const id of ids) {
const oldState = await this.findOne(id);
if (oldState && oldState.category !== category) {
const updatedNextBlocks = oldState.nextBlocks?.filter((nextBlock) =>
const blocks = await this.find({
_id: { $in: ids },
category: { $ne: category },
});
for (const { id, nextBlocks, attachedBlock } of blocks) {
const updatedNextBlocks = nextBlocks.filter((nextBlock) =>
ids.includes(nextBlock),
);
const updatedAttachedBlock = ids.includes(oldState.attachedBlock || '')
? oldState.attachedBlock
const updatedAttachedBlock = ids.includes(attachedBlock || '')
? attachedBlock
: null;
await this.updateOne(id, {
@ -189,7 +192,6 @@ export class BlockRepository extends BaseRepository<
});
}
}
}
/**
* Updates blocks outside the specified category scope by removing references to the provided IDs.