cldellow / datasette-ui-extras

Add editing UI and other power-user features to Datasette.
Apache License 2.0
12 stars 1 forks source link

Improve cacheability of facet requests #42

Closed cldellow closed 1 year ago

cldellow commented 1 year ago

We compute facets by making JSON requests, one per each facet.

For example, faceting by creation_date and tags results in these two requests:

https://dux-demo.fly.dev/superuser/posts.json
  ?_sort=id
  &_facet_year=creation_date
  &_facet_array=tags
  &post_type__exact=question
  &_size=0
  &_nocount=1
  &_dux_facet=_facet_year           <--
  &_dux_facet_column=creation_date  <--
https://dux-demo.fly.dev/superuser/posts.json
  ?_sort=id
  &_facet_year=creation_date
  &_facet_array=tags
  &post_type__exact=question
  &_size=0
  &_nocount=1
  &_dux_facet=_facet_array <--
  &_dux_facet_column=tags  <--

Even though each request is only for a single facet, we include both _facet_year=creation_date and _facet_array=tags in both requests so that the URLs that get constructed are correct.

If you remove the creation_date facet, the request for the tags facet will have a different set of parameters:

https://dux-demo.fly.dev/superuser/posts.json
  ?_sort=id
  &_facet_array=tags
  &post_type__exact=question
  &_size=0
  &_nocount=1
  &_dux_facet=_facet_array
  &_dux_facet_column=tags

This means that even though we have a perfectly good cached response for this facet, we won't be able to use it.

A possible alternative would be to omit all _facet_* parameters except the facet under consideration, and then teach fixupToggleUrl how to re-add the other columns.

A good solution would also re-add the deleted parameters in the same location to ensure a high cache rate. This feels pretty involved for what is probably not that big of a problem.

cldellow commented 1 year ago

Too fiddly for too small of a problem