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,
|
category: string,
|
||||||
ids: string[],
|
ids: string[],
|
||||||
): Promise<void> {
|
): Promise<void> {
|
||||||
for (const id of ids) {
|
const blocks = await this.find({
|
||||||
const oldState = await this.findOne(id);
|
_id: { $in: ids },
|
||||||
if (oldState && oldState.category !== category) {
|
category: { $ne: category },
|
||||||
const updatedNextBlocks = oldState.nextBlocks?.filter((nextBlock) =>
|
});
|
||||||
ids.includes(nextBlock),
|
|
||||||
);
|
|
||||||
|
|
||||||
const updatedAttachedBlock = ids.includes(oldState.attachedBlock || '')
|
for (const { id, nextBlocks, attachedBlock } of blocks) {
|
||||||
? oldState.attachedBlock
|
const updatedNextBlocks = nextBlocks.filter((nextBlock) =>
|
||||||
: null;
|
ids.includes(nextBlock),
|
||||||
|
);
|
||||||
|
|
||||||
await this.updateOne(id, {
|
const updatedAttachedBlock = ids.includes(attachedBlock || '')
|
||||||
nextBlocks: updatedNextBlocks,
|
? attachedBlock
|
||||||
attachedBlock: updatedAttachedBlock,
|
: null;
|
||||||
});
|
|
||||||
}
|
await this.updateOne(id, {
|
||||||
|
nextBlocks: updatedNextBlocks,
|
||||||
|
attachedBlock: updatedAttachedBlock,
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user