I am creating an API for my Instagram clone app. I am using a postgres database with knexjs.
I have four tables for my app i.e. users, posts and likes.
I am building a profile page where user info is displayed. Profile page will display info from all the tables.
My question is whether making five separate queries to the database affect loading times of the profile page? I will be making Count, group by etc. queries that can not be merged or joined together.
Or is there any other alternative that won't affect the performance or the loading times?
Here is my route code: -
router.get('/:id', async (req, res) => {
const userID = req.params.id;
//Get the profile info from the db
const profile = await getUserInfo(userID);
if (profile.length === 0) {
return res.json({
errors: "No user found!"
})
}
//Get last 9 created post ordered by creation date in DESC order
const posts = await getUserPosts(userID)
//Get posts count
const count = await getUserPostCount(userID)
return res.json({
profile: profile[0],
posts,
postCount: count[0].count
}).status(201);
})
You can see there are three constants profile, posts and count which are making individual queries. Is that okay?
My full source code is here: - https://github.com/ajaybirbal/photogram-backend/blob/main/routes/profile.js