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
|
// client.service.ts
|
||||||
public async killDeadClients(): Promise<boolean> {
|
public async killDeadClients(): Promise<boolean> {
|
||||||
const BATCH_SIZE = 500;
|
const BATCH_SIZE = 10000;
|
||||||
|
|
||||||
return this.dataSource.transaction('REPEATABLE READ', async (manager) => {
|
return this.dataSource.transaction('READ COMMITTED', async (manager) => { // ← CHANGE HERE
|
||||||
// IMPORTANT: We use raw SQL for the SELECT + SKIP LOCKED
|
|
||||||
// This bypasses every TypeORM locking bug with inheritance
|
|
||||||
const deadClients: { id: string }[] = await manager.query(`
|
const deadClients: { id: string }[] = await manager.query(`
|
||||||
SELECT id
|
SELECT id
|
||||||
FROM client_entity
|
FROM client_entity
|
||||||
@@ -41,17 +39,14 @@ export class ClientService {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
const ids = deadClients.map(c => c.id);
|
|
||||||
|
|
||||||
// Now the update is safe and super fast
|
|
||||||
await manager
|
await manager
|
||||||
.createQueryBuilder()
|
.createQueryBuilder()
|
||||||
.update(ClientEntity)
|
.update(ClientEntity)
|
||||||
.set({ deletedAt: () => 'NOW()' })
|
.set({ deletedAt: () => 'NOW()' })
|
||||||
.whereInIds(ids)
|
.whereInIds(deadClients.map(c => c.id))
|
||||||
.execute();
|
.execute();
|
||||||
|
|
||||||
console.log(`Killed ${deadClients.length}`);
|
console.log(`Killed ${deadClients.length} dead clients`);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user