irfanzainudin / pantunis-api

https://pantunis-api.vercel.app
MIT License
2 stars 1 forks source link

Pagination #2

Closed irfanzainudin closed 1 month ago

irfanzainudin commented 1 month ago

Overview

Right now, if you search for any words/terms/phrases and the results have a size of 1000, the API will return 1000 which impacts performance. For me, the performance cost is not an issue at all, people can wait. Until the performance cost is a problem ie. the API becomes very slow in responding to requests, I will not treat it as a problem.

However, it is a problem when you try to search using an empty string because the frontend crashes and it becomes blank.

So at this point in time, Pantunis needs pagination only for the empty string case.

How to build it?

I honestly don't know how to do pagination, but I'm pretty sure there are tons of tutorials out there. A good starting point would be to search for "pagination using expressjs and sqlite".

Tests

(Testing framework still not up: most probably Jest)

irfanzainudin commented 1 month ago

I know SQL has a LIMIT clause that can be used to specify the number of records returned.

Since we're using knexjs, I looked it up and sure enough, knex has the LIMIT clause built-in (refer here).

Credit to this SO answer.

So I'm gonna close this as commit af3d966 fixes this problem.