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
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.9 Replies
and i would be making pointless requests for 100 exercises.
here a clip of the aforementioned "instant feedback"
Unknown User•3y ago
Message Not Public
Sign In & Join Server To View
it does, it hurts me lol
Unknown User•3y ago
Message Not Public
Sign In & Join Server To View
in my case the data is 100% static.
is it still the case.
i understand server filtering is probably 100% better advised if your searching dynamic data (reddit posts, twitch stream titles, etc)
Unknown User•3y ago
Message Not Public
Sign In & Join Server To View
yea that table in particular is static. i still need a server for rest of the tables that contain dynamic user specific data.
but yea like qc warrior said. it would increase my first load drastically since it would prolly be like ~230kb. i dont know how to dynamically fetch, it, i suppose i could "suspend" the query, untill the page loads.
Unknown User•3y ago
Message Not Public
Sign In & Join Server To View