internetarchive / openlibrary

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

Solr Performance: Lazy-load some facets #7271

Closed cdrini closed 1 month ago

cdrini commented 1 year ago

Facets are expensive and have performance implications. Make some of the facets collapsed by default, and only load in when the user expands them.

Requires adding a way to fetch facets from a search endpoint.

Initial Solution

For now, the path forward is (perhaps led by @jimchamp):

Screenshot 2024-05-09 at 12 32 46 PM

Phases

  1. Simply move the facet sidebar into its own template with loading and defaults (even if we’re not using them in step 1.
  2. Refactor the /plugins/worksearch/code.py so it’s possible to make 2 separate queries: facet counts (no results) and results (no facet counts) while preserving ability to support facet counts + results
  3. Create partial which returns facets template w/ no results, just facet counts… Update the main template to use results, no facet counts

Polished Solution

This should probably be led by @cdrini

mekarpeles commented 4 months ago

In our https://github.com/internetarchive/openlibrary/blob/master/openlibrary/plugins/worksearch/code.py#L495-L502 that powers the /search endpoint, we ultimately do a do_search which uses run_solr_query to generate search results and facets for the work_search.html template (otherwise if there are no params, we fallback to an empty SearchResponse object).

We presumably want to control do_search from the search GET so that facets are False.

This will allow us to populate the search page without the facets initially.

cc: @cdrini we may need your help figuring out how to create or update the search API / endpoints to only return facet counts (no search results)

cdrini commented 4 months ago

^ Set the rows=0 ; on the do_search; that's the solr recommended way to only get facet data :+1: