refactor(markdown): optimize article extraction with Promise.all
- Refactored the extractAllArticle method to utilize Promise.all for concurrent fetching of posts, notes, and pages, improving performance and code readability. - Simplified the return structure by directly assigning the results of the Promise.all call. Signed-off-by: Innei <tukon479@gmail.com>
This commit is contained in:
@@ -155,10 +155,15 @@ export class MarkdownService {
|
||||
}
|
||||
|
||||
async extractAllArticle() {
|
||||
const [posts, notes, pages] = await Promise.all([
|
||||
this.postModel.find().populate('category').lean(),
|
||||
this.noteModel.find().lean(),
|
||||
this.pageModel.find().lean(),
|
||||
])
|
||||
return {
|
||||
posts: await this.postModel.find().populate('category').lean(),
|
||||
notes: await this.noteModel.find().lean(),
|
||||
pages: await this.pageModel.find().lean(),
|
||||
posts,
|
||||
notes,
|
||||
pages,
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user