Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: switch console.time() to log #1062

Merged
merged 1 commit into from
Dec 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading