From 47a5459637dbab1c0db6d3263bdc8b05fc465199 Mon Sep 17 00:00:00 2001 From: Lauryn Menard Date: Thu, 1 Feb 2024 15:07:04 +0100 Subject: [PATCH] zilencer: Add index on RemoteInstallationCount for remote activity. When profiling the database query in `remote_activity.py`, push_forwarded_count was identified as an expensive part of the overall work. Adds an index on RemoteInstallationCount so this is more efficient. --- ...count_add_mobile_pushes_forwarded_index.py | 21 +++++++++++++++++++ zilencer/models.py | 7 +++++++ 2 files changed, 28 insertions(+) create mode 100644 zilencer/migrations/0058_remoteinstallationcount_add_mobile_pushes_forwarded_index.py diff --git a/zilencer/migrations/0058_remoteinstallationcount_add_mobile_pushes_forwarded_index.py b/zilencer/migrations/0058_remoteinstallationcount_add_mobile_pushes_forwarded_index.py new file mode 100644 index 0000000000..0424c8ffe0 --- /dev/null +++ b/zilencer/migrations/0058_remoteinstallationcount_add_mobile_pushes_forwarded_index.py @@ -0,0 +1,21 @@ +# Generated by Django 4.2.9 on 2024-02-01 13:58 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ("zilencer", "0057_remoterealm_last_request_timestamp_and_more"), + ] + + operations = [ + migrations.AddIndex( + model_name="remoteinstallationcount", + index=models.Index( + condition=models.Q(("property", "mobile_pushes_forwarded::day")), + fields=["server_id", "end_time"], + name="zilencer_remoteinstallationcount_server_end_time_mobile_pushes_forwarded", + ), + ), + ] diff --git a/zilencer/models.py b/zilencer/models.py index eb3f7785d7..e0fb655efb 100644 --- a/zilencer/models.py +++ b/zilencer/models.py @@ -373,6 +373,13 @@ class RemoteInstallationCount(BaseRemoteCount): name="unique_remote_installation_count_server_id_remote_id", ), ] + indexes = [ + models.Index( + fields=["server_id", "end_time"], + condition=Q(property="mobile_pushes_forwarded::day"), + name="zilencer_remoteinstallationcount_server_end_time_mobile_pushes_forwarded", + ) + ] @override def __str__(self) -> str: