-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
14 changed files
with
235 additions
and
88 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
import { prisma } from "@td/prisma"; | ||
import { AuthType, EmitterType, Prisma } from "@prisma/client"; | ||
import { logger } from "@td/logger"; | ||
import { deleteBsd } from "../../common/elastic"; | ||
import { closeQueues } from "../../queue/producers"; | ||
|
||
async function exitScript() { | ||
logger.info("Done reindexAllInBulk script, exiting"); | ||
await prisma.$disconnect(); | ||
await closeQueues(); | ||
process.exit(0); | ||
} | ||
|
||
// ensure deleted orphans appendix1 are removed from ES | ||
(async function () { | ||
const CHUNK_SIZE = 200; | ||
|
||
const where: Prisma.FormWhereInput = { | ||
emitterType: EmitterType.APPENDIX1_PRODUCER, | ||
isDeleted: true, | ||
groupedIn: { none: {} } | ||
}; | ||
const orphansCount = await prisma.form.count({ where }); | ||
|
||
let cursor: string | null = null; | ||
|
||
for (let i = 0; i < orphansCount; i += CHUNK_SIZE) { | ||
console.log(`Chunk ${i + 1}`); | ||
|
||
const orphans = await prisma.form.findMany({ | ||
where, | ||
orderBy: { id: "asc" }, | ||
take: CHUNK_SIZE, | ||
select: { id: true }, | ||
...(cursor ? { skip: 1, cursor: { id: cursor } } : {}) | ||
}); | ||
|
||
cursor = orphans[orphans.length - 1].id; | ||
|
||
const orphansIds = orphans.map(form => form.id); | ||
|
||
for (const id of orphansIds) { | ||
console.log(`Removing ${id}`); | ||
await deleteBsd({ id }, { user: { auth: AuthType.BEARER } } as any); | ||
} | ||
} | ||
|
||
await exitScript(); | ||
})(); |
Oops, something went wrong.