harvard-lil / perma

Indelible links
420 stars 71 forks source link

Work around expensive query from Django 3.2 #3277

Closed rebeccacremona closed 1 year ago

rebeccacremona commented 1 year ago

This PR introduces a work-around for https://github.com/harvard-lil/perma/issues/3276.

It's a pretty simple work-around.

Instead of asking for AND NOT perma_linkuser.is_active AND NOT perma_linkuser.is_confirmed, which takes 25-30 seconds, we ask for AND NOT perma_linkuser.is_active AND perma_linkuser.is_confirmed, which takes 1-2 seconds, and subtract the answer from the other numbers we have around to get the same result.

1-2 seconds is still slow... but it's not that bad. And, this only comes up for admins, who almost never need to look at this page (and indeed, can use the Django admin instead if they do indeed need this information). So, I think this is good enough for now.

But we can certainly readdress if it still seems to be causing problems, or if it starts causing problems again as the number of Sponsored Users grows. This page is long overdue for redesign and refactoring anyway.

Many thanks to @bensteinberg and @lizadaly for help and for moral support debugging this 🙏 !!!