mirror of
https://github.com/benjamin-wilson/public-pool.git
synced 2026-09-29 09:05:06 -07:00
killDeadClients
This commit is contained in:
@@ -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;
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user