Skip to content
This repository was archived by the owner on Mar 3, 2020. It is now read-only.

Commit b0b36cf

Browse files
committed
Log query duration in trending API
1 parent e937121 commit b0b36cf

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

velog-backend/src/router/posts/posts.ctrl.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -452,18 +452,24 @@ export const listTrendingPosts = async (ctx: Context) => {
452452

453453
// check cursor
454454
try {
455+
console.time('getTrendingPosts');
455456
const postIds = await getTrendingPosts(offset || 0);
457+
console.timeEnd('getTrendingPosts');
456458
if (!postIds || postIds.length === 0) {
457459
ctx.body = [];
458460
return;
459461
}
462+
console.time('readPostsByIds');
460463
const posts = await Post.readPostsByIds(postIds.map(postId => postId.post_id));
464+
console.timeEnd('readPostsByIds');
461465
const data = posts
462466
.map(serializePost)
463467
.map(post => ({ ...post, body: formatShortDescription(post.body) }));
464468

465469
// retrieve commentCounts and inject
470+
console.time('getCommentCounts');
466471
const commentCounts = await getCommentCountsOfPosts(posts.map(p => p.id));
472+
console.timeEnd('getCommentCounts');
467473
ctx.body = injectCommentCounts(data, commentCounts);
468474
} catch (e) {
469475
ctx.throw(500, e);

0 commit comments

Comments
 (0)