Skip to content

Commit 85646b7

Browse files
committed
refactor: improve execution time logging in AxiosService and UsersRepository
1 parent 515e309 commit 85646b7

File tree

3 files changed

+12
-12
lines changed

3 files changed

+12
-12
lines changed

src/common/axios/axios.service.ts

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -90,17 +90,11 @@ export class AxiosService {
9090
const nodeUrl = this.getNodeUrl(url, StartXrayCommand.url, port);
9191

9292
try {
93-
// TODO: Remove this log
94-
this.logger.log(
95-
`Uncompressed data size: ${prettyBytesUtil(JSON.stringify(data).length)}`,
96-
);
97-
98-
const ct = getTime();
99-
93+
const startTime = getTime();
10094
const compressedData = await this.compressData(data);
10195

10296
this.logger.log(
103-
`Compressed data in: ${formatExecutionTime(ct)}, size: ${prettyBytesUtil(compressedData.length)}`,
97+
`[ZSTD] ${formatExecutionTime(startTime)} | ${prettyBytesUtil(compressedData.length)}`,
10498
);
10599

106100
const response = await this.axiosInstance.post<StartXrayCommand.Response>(
Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,14 @@
11
import ms from 'enhanced-ms';
22

33
export function formatExecutionTime(startTime: number): string {
4-
return ms(Date.now() - startTime, 'short') || '0ms';
4+
return (
5+
ms(performance.now() - startTime, {
6+
extends: 'short',
7+
includeMs: true,
8+
}) || '0ms'
9+
);
510
}
611

712
export function getTime(): number {
8-
return Date.now();
13+
return performance.now();
914
}

src/modules/users/repositories/users.repository.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import { TransactionalAdapterPrisma } from '@nestjs-cls/transactional-adapter-pr
99
import { TransactionHost } from '@nestjs-cls/transactional';
1010
import { Injectable, Logger } from '@nestjs/common';
1111

12+
import { formatExecutionTime, getTime } from '@common/utils/get-elapsed-time';
1213
import { TxKyselyService } from '@common/database/tx-kysely.service';
1314
import { getKyselyUuid } from '@common/helpers/kysely';
1415
import { GetAllUsersCommand } from '@libs/contracts/commands';
@@ -733,10 +734,10 @@ export class UsersRepository {
733734
.orderBy(sql<string>`users.t_id asc`)
734735
.limit(BATCH_SIZE);
735736

736-
const start = performance.now();
737+
const startTime = getTime();
737738
const result = await builder.execute();
738739
this.logger.log(
739-
`[getUsersForConfigStream] ${performance.now() - start}ms, length: ${result.length}`,
740+
`[getUsersForConfigStream] ${formatExecutionTime(startTime)}, length: ${result.length}`,
740741
);
741742

742743
if (result.length < BATCH_SIZE) {

0 commit comments

Comments
 (0)