remote-billing: Add index to RemoteRealmAuditLog for billing events.

When profiling the database queries for the remote support view,
getting the user counts for remote realms was identifed as an
expensive query. Adds an index on RemoteRealmAuditLog to improve
this relatively common query for remote billing information.
This commit is contained in:
Lauryn Menard 2024-02-21 21:12:29 +01:00 committed by Tim Abbott
parent bf4933942c
commit e5c92a1ee6
2 changed files with 26 additions and 0 deletions

View File

@ -0,0 +1,21 @@
# Generated by Django 4.2.9 on 2024-02-20 12:04
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
("zilencer", "0058_remoteinstallationcount_add_mobile_pushes_forwarded_index"),
]
operations = [
migrations.AddIndex(
model_name="remoterealmauditlog",
index=models.Index(
condition=models.Q(("event_type__in", [101, 102, 103, 104, 105, 201, 202, 229])),
fields=["remote_realm_id", "id"],
name="zilencer_remoterealmauditlog_synced_billing_events",
),
),
]

View File

@ -333,6 +333,11 @@ class RemoteRealmAuditLog(AbstractRealmAuditLog):
condition=Q(remote_realm__isnull=True),
name="zilencer_remoterealmauditlog_server",
),
models.Index(
fields=["remote_realm_id", "id"],
condition=Q(event_type__in=AbstractRealmAuditLog.SYNCED_BILLING_EVENTS),
name="zilencer_remoterealmauditlog_synced_billing_events",
),
]