Skip to content

Conversation

@StefanyRomeroV
Copy link
Collaborator

No description provided.

Copy link
Collaborator

@LucasIversen LucasIversen left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi Stefany. I've got a few comments, mainly regarding how we fetch data. If anything needs further explaining, you can always write me on slack 👌

try {
let meals;
if (!req.query.availableReservations) {
meals = await getAllMeals();
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see what you're doing. It's sometimes easier to filter on an array in javascript than expanding the knex query. However, this also means that we always fetch every single meal, even when we maybe only need to return a couple of them. Now imagine we have 10000 meals, that's a lot of data to fetch every time. Therefore, it's better practice to make the query only fetch what you need.

};

//sortDir
if (req.query.sortDir) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The sortDir should only be used if the sortKey is also used.

try {
const mealId = +req.params.id;
const reqBody = req.body;
const meal = await knex("meals").where({ id: mealId }).first();
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can avoid this fetch by checking the updatedMealNum instead

//get/reviews/:id
const getReviewById = async (id) => {
try {
const allReviews = await getAllReviews();
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here we also fetch all the reviews only to return a single one. Let's instead only fetch the meal with the id instead

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants