I think when fetching all blogs for home page, you should only fetch the data which you will show for each blog rather than fetching the whole blog.
Lets assume each of your blog has following fields:
{
"title" : "Title of blog",
"body" : "This is my blog, ...."
"comments": [comment1, comment2, ...]
"upvotes" : [],
"downvotes" : [],
"author" : ObjectId("ref to the author schema"),
"time" : 10:30 PM
}
on home page, i'm assuming you only need to show the author, title, time and some lines of the body so you need to only fetch those instead of getting the whole blog.
For that you can use .select() function of mongoose:
const blogs = await Blogs.find({}).select({ title: 1, time: 1, body: 1, author: 1 });
This way, you will only be getting the data you require. By implementing this, when a user clicks on a blog to view it, you can re-fetch the whole blog and get the latest result (in case the blog was updated or new comments/votes were added, the changes will be reflected).
Hope this answers your question.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…