mirror of https://github.com/zulip/zulip.git
zerver: Add a partial audit log index for counting active users.
This index is used by `active_users_audit:is_bot:day`, and provides roughly a 2x speedup. The existing `zerver_realmauditlog_realm__event_type__event_time` is used if there is a realm limit, but the standard statistics fill runs for all realms at once, and thus cannot use it.
This commit is contained in:
parent
48d3601649
commit
3ea0d73182
|
@ -0,0 +1,26 @@
|
||||||
|
from django.contrib.postgres.operations import AddIndexConcurrently
|
||||||
|
from django.db import migrations, models
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
atomic = False
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
("zerver", "0527_presencesequence"),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
AddIndexConcurrently(
|
||||||
|
model_name="realmauditlog",
|
||||||
|
index=models.Index(
|
||||||
|
# event_type__in:
|
||||||
|
# AbstractRealmAuditLog.USER_CREATED,
|
||||||
|
# AbstractRealmAuditLog.USER_ACTIVATED,
|
||||||
|
# AbstractRealmAuditLog.USER_DEACTIVATED,
|
||||||
|
# AbstractRealmAuditLog.USER_REACTIVATED,
|
||||||
|
condition=models.Q(("event_type__in", [101, 102, 103, 104])),
|
||||||
|
fields=["modified_user", "event_time"],
|
||||||
|
name="zerver_realmauditlog_user_activations_idx",
|
||||||
|
),
|
||||||
|
),
|
||||||
|
]
|
|
@ -242,6 +242,19 @@ class RealmAuditLog(AbstractRealmAuditLog):
|
||||||
]
|
]
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
|
models.Index(
|
||||||
|
# Used in analytics/lib/counts.py for computing active users for realm_active_humans
|
||||||
|
name="zerver_realmauditlog_user_activations_idx",
|
||||||
|
fields=["modified_user", "event_time"],
|
||||||
|
condition=Q(
|
||||||
|
event_type__in=[
|
||||||
|
AbstractRealmAuditLog.USER_CREATED,
|
||||||
|
AbstractRealmAuditLog.USER_ACTIVATED,
|
||||||
|
AbstractRealmAuditLog.USER_DEACTIVATED,
|
||||||
|
AbstractRealmAuditLog.USER_REACTIVATED,
|
||||||
|
]
|
||||||
|
),
|
||||||
|
),
|
||||||
]
|
]
|
||||||
|
|
||||||
@override
|
@override
|
||||||
|
|
Loading…
Reference in New Issue