From 353e1a20166a0e12bdfa01b7b84d99fe8932b162 Mon Sep 17 00:00:00 2001 From: Mateusz Mandera Date: Sun, 14 Feb 2021 00:12:54 +0100 Subject: [PATCH] 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. --- zerver/lib/actions.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/zerver/lib/actions.py b/zerver/lib/actions.py index 2be9fcf5a5..8c2315ab07 100644 --- a/zerver/lib/actions.py +++ b/zerver/lib/actions.py @@ -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