migrations: Subscription.is_user_active denormalization - final step.

With the previous two commits deployed, we're ready to use the
denormalization to optimize the query.

With dev environment db prepared using
./manage.py populate_db --extra-users=2000 --extra-streams=400
this takes the execution time of the query in
bulk_get_subscriber_user_ids from 1.5-1.6s to 0.4-0.5s on my machine.
This commit is contained in:
Mateusz Mandera 2021-02-14 00:12:54 +01:00 committed by Tim Abbott
parent 1e37fde59f
commit 353e1a2016
1 changed files with 1 additions and 3 deletions

View File

@ -3161,12 +3161,10 @@ def bulk_get_subscriber_user_ids(
zerver_subscription.user_profile_id
FROM
zerver_subscription
INNER JOIN zerver_userprofile ON
zerver_userprofile.id = zerver_subscription.user_profile_id
WHERE
zerver_subscription.recipient_id in %(recipient_ids)s AND
zerver_subscription.active AND
zerver_userprofile.is_active
zerver_subscription.is_user_active
ORDER BY
zerver_subscription.recipient_id,
zerver_subscription.user_profile_id