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:
Innei
2025-05-07 22:51:41 +08:00
parent e80b77662b
commit f054fe5c4c

View File

@@ -155,10 +155,15 @@ export class MarkdownService {
} }
async extractAllArticle() { async extractAllArticle() {
const [posts, notes, pages] = await Promise.all([
this.postModel.find().populate('category').lean(),
this.noteModel.find().lean(),
this.pageModel.find().lean(),
])
return { return {
posts: await this.postModel.find().populate('category').lean(), posts,
notes: await this.noteModel.find().lean(), notes,
pages: await this.pageModel.find().lean(), pages,
} }
} }