killDeadClients

This commit is contained in:
Ben
2025-11-21 20:56:27 -05:00
parent 1b0f3f52d8
commit 63a1618f26
+4 -9
View File
@@ -22,11 +22,9 @@ export class ClientService {
// client.service.ts
public async killDeadClients(): Promise<boolean> {
const BATCH_SIZE = 500;
const BATCH_SIZE = 10000;
return this.dataSource.transaction('REPEATABLE READ', async (manager) => {
// IMPORTANT: We use raw SQL for the SELECT + SKIP LOCKED
// This bypasses every TypeORM locking bug with inheritance
return this.dataSource.transaction('READ COMMITTED', async (manager) => { // ← CHANGE HERE
const deadClients: { id: string }[] = await manager.query(`
SELECT id
FROM client_entity
@@ -41,17 +39,14 @@ export class ClientService {
return false;
}
const ids = deadClients.map(c => c.id);
// Now the update is safe and super fast
await manager
.createQueryBuilder()
.update(ClientEntity)
.set({ deletedAt: () => 'NOW()' })
.whereInIds(ids)
.whereInIds(deadClients.map(c => c.id))
.execute();
console.log(`Killed ${deadClients.length}`);
console.log(`Killed ${deadClients.length} dead clients`);
return true;
});