internetarchive / openlibrary

One webpage for every book ever published!
https://openlibrary.org
GNU Affero General Public License v3.0
5.25k stars 1.39k forks source link

Improve no search results page by caching "search inside" response #10051

Open RayBB opened 6 days ago

RayBB commented 6 days ago

Problem

The video explains it well. In short, we don't cache the "search inside" request so when people go to different search types with no result, it loads each time for 1-2 seconds. A small improvement would be to cache the search inside partial endpoint for a while. Maybe 1 hour? Seems unlikely to change often but also don't want to make a cache last a long time for no reason.

Video (with audio)

https://github.com/user-attachments/assets/cfd6c47d-8dc2-4436-aa54-553956aa4c10

Reproducing the bug

  1. Go to https://openlibrary.org/search/authors?q=%22cory+doctorow+1234%22
  2. Click the different tabs, see the "search inside" loading bars

Context

n/a

Breakdown

Requirements Checklist

Related files

*

Stakeholders

Instructions for Contributors

cdrini commented 6 days ago

Nice good idea! I think we should cache this by setting the HTTP headers to cache this response on the client side for a short time (maybe like 5min), but only for the FullTextSearch partial and only if there's no error.

(Note shorter time, since it's rather unlikely that a user will hit the search inside multiple times, so it's not worth taking up valuable storage space on their machine for this cache for any extended period of time!)

asharan2buff commented 6 days ago

Can I take this up?

weifanwu commented 4 days ago

Hi @RayBB, I am new to this project, i wonder if I can take this issue? thanks!