Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

133
Visualizações
Postgres querying related performance question? I am querying from three different tables and merging result

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

about 4 years ago · Juan Pablo Isaza
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda