models: Add (realm, create_time) index for the Attachment table.

This commit is contained in:
Mateusz Mandera 2024-05-08 03:18:31 +02:00 committed by Tim Abbott
parent 224ea3aaed
commit 4c4a443002
2 changed files with 32 additions and 0 deletions

View File

@ -0,0 +1,23 @@
# Generated by Django 5.0.6 on 2024-05-08 01:16
from django.contrib.postgres.operations import AddIndexConcurrently
from django.db import migrations, models
class Migration(migrations.Migration):
atomic = False
dependencies = [
("zerver", "0519_archivetransaction_restored_timestamp"),
]
operations = [
AddIndexConcurrently(
model_name="attachment",
index=models.Index(
models.F("realm"),
models.F("create_time"),
name="zerver_attachment_realm_create_time",
),
),
]

View File

@ -713,6 +713,15 @@ class Attachment(AbstractAttachment):
# because ScheduledMessage is not subject to archiving. # because ScheduledMessage is not subject to archiving.
scheduled_messages = models.ManyToManyField("zerver.ScheduledMessage") scheduled_messages = models.ManyToManyField("zerver.ScheduledMessage")
class Meta:
indexes = [
models.Index(
"realm",
"create_time",
name="zerver_attachment_realm_create_time",
),
]
def is_claimed(self) -> bool: def is_claimed(self) -> bool:
return self.messages.exists() or self.scheduled_messages.exists() return self.messages.exists() or self.scheduled_messages.exists()