From 59e0f360e766c867882abe37942e8e02527e12cd Mon Sep 17 00:00:00 2001 From: Steven Date: Thu, 5 Dec 2024 08:52:58 -0500 Subject: [PATCH] chore: switch console.time() to log --- src/util/backend/db-redis.ts | 12 ++++++------ src/util/npm-api.ts | 4 ++-- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/util/backend/db-redis.ts b/src/util/backend/db-redis.ts index 9e7247c0..1189ae5e 100644 --- a/src/util/backend/db-redis.ts +++ b/src/util/backend/db-redis.ts @@ -21,7 +21,7 @@ client.on('error', err => { }); export async function findAll(name: string) { - console.time('findAll (redis)'); + const startTime = Date.now(); const reply = await client.hgetall(name); const obj: { [key: string]: PkgSize } = {}; for (let version in reply) { @@ -30,12 +30,12 @@ export async function findAll(name: string) { payload.version = version; obj[version] = payload; } - console.timeEnd('findAll (redis)'); + console.log(`findAll (redis) ${Date.now() - startTime}ms`); return obj; } export async function findOne(name: string, version: string) { - console.time('findOne (redis)'); + const startTime = Date.now(); const reply = await client.hget(name, version); if (!reply) { @@ -46,15 +46,15 @@ export async function findOne(name: string, version: string) { record.name = name; record.version = version; - console.timeEnd('findOne (redis)'); + console.log(`findOne (redis) ${Date.now() - startTime}ms`); return record; } export async function insert(data: PkgSize) { - console.time('insert (redis)'); + const startTime = Date.now(); const { name, version, ...payload } = data; const value = JSON.stringify(payload); const reply = await client.hset(name, version, value); - console.timeEnd('insert (redis)'); + console.log(`insert (redis) ${Date.now() - startTime}ms`); return reply; } diff --git a/src/util/npm-api.ts b/src/util/npm-api.ts index 2f8ec6b0..74250bae 100644 --- a/src/util/npm-api.ts +++ b/src/util/npm-api.ts @@ -20,9 +20,9 @@ export async function fetchManifest(name: string) { } console.log('lrucache miss'); const encodedPackage = escapePackageName(name); - console.time('fetchJSON'); + const startTime = Date.now(); const manifest = await fetchJSON(`${NPM_REGISTRY_URL}/${encodedPackage}`); - console.timeEnd('fetchJSON'); + console.log(`fetchJSON ${Date.now() - startTime}ms`); if (!isManifest(manifest)) { throw new NotFoundError({ resource: name }); }