Skip to content

Commit

Permalink
chore: switch console.time() to log
Browse files Browse the repository at this point in the history
  • Loading branch information
styfle committed Dec 5, 2024
1 parent 6b64220 commit 59e0f36
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
12 changes: 6 additions & 6 deletions src/util/backend/db-redis.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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) {
Expand All @@ -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;
}
4 changes: 2 additions & 2 deletions src/util/npm-api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 });
}
Expand Down

0 comments on commit 59e0f36

Please sign in to comment.