jeudi 18 avril 2019

One specialized Function or Three generalized Functions?

I'm in the process of adding a new feature to existing software.

The feature requires some data to be fetched from the database. I could do this in 2 ways:

  1. Use three existing php scripts of which each fetches exactly ONE row of data from ONE Table. Each php script will give me some overfetch. On the front-end, I will then have to pick the data I need from each response.
  2. Write a new php script which will use a JOIN to fetch all the data I need in ONE query and then return it to the front-end.

I now wonder which one of the two ways would be deemed "best practice" or at least "better practice". The first way probably has more impact on the server ressources because three calls instead of one occur. However, each call only executes only one very simple MYSQL query. The second way probably takes some load from the serverside (at least that would be my guess), but I can't really assess how much and if this gain is worth adding a highly specialized piece of code to the codebase.

I would be grateful for your input on this :=)

Aucun commentaire:

Enregistrer un commentaire