perf: cache author for faster lookup
This commit is contained in:
parent
cd0f38764d
commit
597d7c8b4c
|
@ -1,6 +1,7 @@
|
|||
import API from "./API";
|
||||
import UI from "./UI";
|
||||
import Input from "./Input";
|
||||
import Author from "./Author";
|
||||
|
||||
const pkg = require("../../package.json");
|
||||
|
||||
|
@ -35,12 +36,20 @@ declare const Prism: any;
|
|||
|
||||
const blogPostContainer = UI.blogPostContainer;
|
||||
if (blogPostContainer) {
|
||||
const authors = [];
|
||||
const template = Handlebars.compile(UI.blogPostTemplate.innerHTML);
|
||||
API.getBlogPostCount().then(async (count) => {
|
||||
for (let i = 0; i < count; i++) {
|
||||
const posts = await API.getBlogPosts(i, 5);
|
||||
for (const post of posts) {
|
||||
const author = await API.getAuthor(post.authorId);
|
||||
let author: Author;
|
||||
if (authors[post.authorId]) {
|
||||
author = authors[post.authorId];
|
||||
} else {
|
||||
author = await API.getAuthor(post.authorId);
|
||||
authors[post.authorId] = author;
|
||||
}
|
||||
|
||||
const card = UI.createBlogPostCard(template, post, author);
|
||||
blogPostContainer.appendChild(card);
|
||||
UI.updateUI(card);
|
||||
|
|
Loading…
Reference in New Issue