readthedocs / readthedocs.org

The source code that powers readthedocs.org
https://readthedocs.org/
MIT License
8.05k stars 3.59k forks source link

Build: reducing query count, prefetching, or intermediate tables #11631

Open agjohnson opened 1 month ago

agjohnson commented 1 month ago

After a few different attempts, it seems like the query complexity added with prefetching causes queries to take much longer than without prefetching (however query count is much much lower, 30 vs 120 queries).

For more background on the removal, see:

The most expensive queries here are getting the latest build (which I think can be external) and getting the latest, non-external, successful build.

Some options here are:

humitos commented 1 month ago

Use an intermediate table for latest/latest successful build on Project. This requires updating the relationship after each build.

Do we need an intermediate table for this? Why not just OneToOne fields on the Project object?

agjohnson commented 1 month ago

Yup, it could be any relation, not necessarily an intermediate table.

humitos commented 1 month ago

I thought a little more about this and I realized that:

agjohnson commented 1 month ago

It's not clear if we need these latest builds to be linked to the Project or to the Version objects

Good point, I think both if we want to speed up both pages. Project and version listing both show the latest build and use has_good_build.