mirror of
https://github.com/hexastack/hexabot
synced 2025-06-26 18:27:28 +00:00
fix(api): optimize preUpdateMany
This commit is contained in:
parent
3813635ee0
commit
69a994f9e3
@ -172,22 +172,24 @@ 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) =>
|
||||
ids.includes(nextBlock),
|
||||
);
|
||||
const blocks = await this.find({
|
||||
_id: { $in: ids },
|
||||
category: { $ne: category },
|
||||
});
|
||||
|
||||
const updatedAttachedBlock = ids.includes(oldState.attachedBlock || '')
|
||||
? oldState.attachedBlock
|
||||
: null;
|
||||
for (const { id, nextBlocks, attachedBlock } of blocks) {
|
||||
const updatedNextBlocks = nextBlocks.filter((nextBlock) =>
|
||||
ids.includes(nextBlock),
|
||||
);
|
||||
|
||||
await this.updateOne(id, {
|
||||
nextBlocks: updatedNextBlocks,
|
||||
attachedBlock: updatedAttachedBlock,
|
||||
});
|
||||
}
|
||||
const updatedAttachedBlock = ids.includes(attachedBlock || '')
|
||||
? attachedBlock
|
||||
: null;
|
||||
|
||||
await this.updateOne(id, {
|
||||
nextBlocks: updatedNextBlocks,
|
||||
attachedBlock: updatedAttachedBlock,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user