Deciding where to do searching & filtering. Frontend or Backend.
So i have a table in my DB called "Exercises". Which contain about 5 feilds of text data.
In total there are about 1700 exercises.
Currently im populating about 300 Exercises in my db for dev purposes. So it was easy enough to have an api route to pull every Exercises into the client (~77kb). And do some basic filtering client-side with some string pattern matching.
This worked fine for now and it was not too much for my phone (primarily a mobile site im working on). With occasionally lag. But ive really enjoyed how snappy the feedback is since im not making search request over the wire to get the results.
However, im thinking of completely populating the database with the full 1700 entries, and that will for sure shit on my phone when doing the naive for loop filtering.
So i spent last night setting up full text search on pgsql to work with prisma to do the filtering on server side. But im affraid of losing that instant response as im typing in the search bar.
Ideally, i would like to have both, the small payload of only receiving the data the matches the search term down the wire, and being able to search through exercises with instant feedback.
I was thinking of pulling in about ~100 exercises on page load (say
and then when a "search" is done, via
Alternatively i could use a library like
https://github.com/nextapps-de/flexsearch
https://github.com/lucaong/minisearch
and completely skip doing any postgres fts, and just incrementally do
In total there are about 1700 exercises.
Currently im populating about 300 Exercises in my db for dev purposes. So it was easy enough to have an api route to pull every Exercises into the client (~77kb). And do some basic filtering client-side with some string pattern matching.
This worked fine for now and it was not too much for my phone (primarily a mobile site im working on). With occasionally lag. But ive really enjoyed how snappy the feedback is since im not making search request over the wire to get the results.
However, im thinking of completely populating the database with the full 1700 entries, and that will for sure shit on my phone when doing the naive for loop filtering.
So i spent last night setting up full text search on pgsql to work with prisma to do the filtering on server side. But im affraid of losing that instant response as im typing in the search bar.
Ideally, i would like to have both, the small payload of only receiving the data the matches the search term down the wire, and being able to search through exercises with instant feedback.
I was thinking of pulling in about ~100 exercises on page load (say
useQuery(['exercises', {take: 100}])and then when a "search" is done, via
useQuery(['exercises.get_by_search', {search_term: "foobar"}]) optimistically push the query data for 'exercises' with the data from the search with a setQueryData. but then this means ill be doing double filtering, unless i completely remove any client side search filtering.Alternatively i could use a library like
https://github.com/nextapps-de/flexsearch
https://github.com/lucaong/minisearch
and completely skip doing any postgres fts, and just incrementally do
useQuery(['exercises', {take: 100}]) whenever a search is performed and no matches are found. But this isnt very smart since its possible there are no matches.