Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions ami/main/migrations/0084_index_detection_occurrence_timestamp.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
from django.contrib.postgres.operations import AddIndexConcurrently
from django.db import migrations, models


class Migration(migrations.Migration):
dependencies = [
("main", "0083_dedupe_taxalist_names"),
]

# AddIndexConcurrently requires running outside a transaction.
atomic = False

operations = [
AddIndexConcurrently(
model_name="detection",
index=models.Index(
fields=["occurrence", "-timestamp"],
name="detection_occurrence_ts_desc",
),
),
]
10 changes: 10 additions & 0 deletions ami/main/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -2778,6 +2778,16 @@ class Meta:
"frame_num",
"timestamp",
]
indexes = [
# Supports /captures/ list ordering and joins from Occurrence to
# its detections by (occurrence_id, timestamp DESC). Django's FK
# index alone is on occurrence_id, which forces a sort on a large
# row set after the join.
models.Index(
fields=["occurrence", "-timestamp"],
name="detection_occurrence_ts_desc",
),
]

def best_classification(self):
# @TODO where is this used?
Expand Down
Loading