mirror of
https://github.com/benjamin-wilson/public-pool.git
synced 2025-03-18 05:41:43 +01:00
trying bulk insert?
This commit is contained in:
parent
45d05f48c1
commit
fe677b88f8
@ -1,15 +1,18 @@
|
||||
import { Injectable } from '@nestjs/common';
|
||||
import { Cron, CronExpression } from '@nestjs/schedule';
|
||||
import { InjectRepository } from '@nestjs/typeorm';
|
||||
import { setTimeout } from 'timers/promises';
|
||||
import { IsNull, LessThan, Repository } from 'typeorm';
|
||||
|
||||
import { ClientEntity } from './client.entity';
|
||||
|
||||
|
||||
|
||||
|
||||
@Injectable()
|
||||
export class ClientService {
|
||||
|
||||
private bulkInsertClients: ClientEntity[] = [];
|
||||
|
||||
constructor(
|
||||
@InjectRepository(ClientEntity)
|
||||
private clientRepository: Repository<ClientEntity>
|
||||
@ -17,6 +20,18 @@ export class ClientService {
|
||||
|
||||
}
|
||||
|
||||
@Cron(CronExpression.EVERY_SECOND)
|
||||
private async bulkInsert() {
|
||||
|
||||
if (this.bulkInsertClients.length < 1) {
|
||||
return;
|
||||
}
|
||||
|
||||
const clientsToInsert = [...this.bulkInsertClients];;
|
||||
this.bulkInsertClients = [];
|
||||
await this.clientRepository.insert(clientsToInsert);
|
||||
}
|
||||
|
||||
public async killDeadClients() {
|
||||
var tenMinutes = new Date(new Date().getTime() - (60 * 60 * 1000));
|
||||
|
||||
@ -36,15 +51,13 @@ export class ClientService {
|
||||
// return await this.clientRepository.save(client);
|
||||
// }
|
||||
|
||||
|
||||
public async insert(partialClient: Partial<ClientEntity>): Promise<ClientEntity> {
|
||||
const insertResult = await this.clientRepository.insert(partialClient);
|
||||
|
||||
const client = {
|
||||
...partialClient,
|
||||
...insertResult.generatedMaps[0]
|
||||
};
|
||||
|
||||
return client as ClientEntity;
|
||||
const client = this.clientRepository.create(partialClient);
|
||||
this.bulkInsertClients.push(client);
|
||||
await setTimeout(2000);
|
||||
return client;
|
||||
}
|
||||
|
||||
public async delete(sessionId: string) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user