mirror of
https://github.com/benjamin-wilson/public-pool.git
synced 2026-09-29 09:05:06 -07:00
Merge branch 'postgresql' of https://github.com/benjamin-wilson/public-pool into postgresql
This commit is contained in:
@@ -1,20 +1,27 @@
|
|||||||
import { Injectable } from '@nestjs/common';
|
import { Injectable, OnModuleDestroy } from '@nestjs/common';
|
||||||
import { InjectRepository } from '@nestjs/typeorm';
|
import { InjectRepository } from '@nestjs/typeorm';
|
||||||
import { Repository } from 'typeorm';
|
import { DataSource, QueryRunner, Repository } from 'typeorm';
|
||||||
|
|
||||||
import { ClientStatisticsEntity } from './client-statistics.entity';
|
import { ClientStatisticsEntity } from './client-statistics.entity';
|
||||||
|
|
||||||
|
|
||||||
@Injectable()
|
@Injectable()
|
||||||
export class ClientStatisticsService {
|
export class ClientStatisticsService implements OnModuleDestroy {
|
||||||
|
|
||||||
|
private readUncommittedQueryRunner: QueryRunner;
|
||||||
|
|
||||||
constructor(
|
constructor(
|
||||||
|
|
||||||
|
private readonly dataSource: DataSource,
|
||||||
@InjectRepository(ClientStatisticsEntity)
|
@InjectRepository(ClientStatisticsEntity)
|
||||||
private clientStatisticsRepository: Repository<ClientStatisticsEntity>,
|
private clientStatisticsRepository: Repository<ClientStatisticsEntity>,
|
||||||
) {
|
) {
|
||||||
|
this.readUncommittedQueryRunner = this.dataSource.createQueryRunner();
|
||||||
|
this.readUncommittedQueryRunner.query('SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED;')
|
||||||
|
}
|
||||||
|
|
||||||
|
onModuleDestroy() {
|
||||||
|
this.readUncommittedQueryRunner.release();
|
||||||
}
|
}
|
||||||
|
|
||||||
public async save(clientStatistic: Partial<ClientStatisticsEntity>) {
|
public async save(clientStatistic: Partial<ClientStatisticsEntity>) {
|
||||||
@@ -47,9 +54,9 @@ export class ClientStatisticsService {
|
|||||||
|
|
||||||
var yesterday = new Date(new Date().getTime() - (24 * 60 * 60 * 1000));
|
var yesterday = new Date(new Date().getTime() - (24 * 60 * 60 * 1000));
|
||||||
|
|
||||||
const query = `
|
|
||||||
SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED;
|
|
||||||
|
|
||||||
|
var result = await this.readUncommittedQueryRunner.query(
|
||||||
|
`
|
||||||
SELECT
|
SELECT
|
||||||
time AS label,
|
time AS label,
|
||||||
ROUND(((SUM(shares) * 4294967296) / 600)) AS data
|
ROUND(((SUM(shares) * 4294967296) / 600)) AS data
|
||||||
@@ -61,11 +68,9 @@ export class ClientStatisticsService {
|
|||||||
time
|
time
|
||||||
ORDER BY
|
ORDER BY
|
||||||
time
|
time
|
||||||
LIMIT 144;
|
LIMIT 144;
|
||||||
|
`
|
||||||
`;
|
);
|
||||||
|
|
||||||
const result: any[] = await this.clientStatisticsRepository.query(query);
|
|
||||||
|
|
||||||
|
|
||||||
return result.map(res => {
|
return result.map(res => {
|
||||||
|
|||||||
Reference in New Issue
Block a user