hiteshchoudhary / apihub

Your own API Hub to learn and master API interaction. Ideal for frontend, mobile dev and backend developers.
https://freeapi.app
Other
6.71k stars 1.08k forks source link

ENHANCEMENT: Public api performance Improvement #119

Closed Mitesh0807 closed 6 months ago

Mitesh0807 commented 7 months ago

Describe the enhancement

In order to pointout the getPublics method (book,cat,dog,meal,randomjoke,randomproduct,stock), we perform data filtering through search key processing. Upon discovering included keys in the query parameters, we proceed with the entire filterout process and eliminate the keys. Alternatively, we can obtain the paginated payload first, which can greatly enhance performance, and then remove the key.

Use Case

No response

Additional Information

suggested solution but there can be more cleaner solution just pointing out this we can process lot less data for removing keys

let booksArray = query
    ? structuredClone(booksJson).filter((book) => {
        return (
          book.searchInfo?.textSnippet.toLowerCase().includes(query) ||
          book.volumeInfo.title?.includes(query) ||
          book.volumeInfo.subtitle?.includes(query)
        );
      })
    : structuredClone(booksJson);

//if (inc && inc[0]?.trim()) {
// booksArray = filterObjectKeys(inc, booksArray);
//}
const paginatedResponse = getPaginatedPayload(booksArray, page, limit)
  const updatedBooks = inc
    ? filterObjectKeys(inc, paginatedBooks.data)
    : paginatedBooks.data;
  return res.status(200).json(
    new ApiResponse(
      200,
      {
        ...paginatedBooks,
        data: updatedBooks,
      },
      "Books fetched successfully"
    )
  );
});

Suggested Tools

No response

Additional Context or Information

Hopefully i submitted issue right way if not please let me know and if provided info is right , i can work on this enhancement

wajeshubham commented 7 months ago

Nice catch @Mitesh0807, yes you are right, this can be optimized. It would be really helpful if you address this issue and open a PR for the same.

Regards, FreeAPI team

Mitesh0807 commented 7 months ago

@wajeshubham sure man!

Mitesh0807 commented 7 months ago

@wajeshubham created pull request for this pls check ! 😊

wajeshubham commented 6 months ago

PR: #125