Skip to content

Commit

Permalink
Set an index for name
Browse files Browse the repository at this point in the history
  • Loading branch information
derneuere committed Mar 29, 2024
1 parent 0cb12b2 commit 837caeb
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 12 deletions.
22 changes: 22 additions & 0 deletions api/migrations/0061_alter_person_name.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# Generated by Django 4.2.11 on 2024-03-29 17:20

import django.core.validators
from django.db import migrations, models


class Migration(migrations.Migration):
dependencies = [
("api", "0060_apply_default_face_cover"),
]

operations = [
migrations.AlterField(
model_name="person",
name="name",
field=models.CharField(
db_index=True,
max_length=128,
validators=[django.core.validators.MinLengthValidator(1)],
),
),
]
2 changes: 1 addition & 1 deletion api/models/person.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class Person(models.Model):
(KIND_UNKNOWN, "Unknown Person"),
)
name = models.CharField(
blank=False, max_length=128, validators=[MinLengthValidator(1)]
blank=False, max_length=128, validators=[MinLengthValidator(1)], db_index=True
)
kind = models.CharField(choices=KIND_CHOICES, max_length=10)
cover_photo = models.ForeignKey(
Expand Down
24 changes: 13 additions & 11 deletions api/views/faces.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,21 +111,23 @@ def get_queryset(self):

queryset = Person.objects.filter(cluster_owner=self.request.user)

queryset = queryset.annotate(
viewable_face_count=Count(
Case(
When(
Q(faces__person_label_is_inferred=inferred)
| Q(faces__person__name=Person.UNKNOWN_PERSON_NAME),
then=1,
),
output_field=IntegerField(),
queryset = (
queryset.annotate(
viewable_face_count=Count(
Case(
When(
Q(faces__person_label_is_inferred=inferred)
| Q(faces__person__name=Person.UNKNOWN_PERSON_NAME),
then=1,
),
output_field=IntegerField(),
)
)
)
.filter(viewable_face_count__gt=0)
.order_by("name")
)

queryset = queryset.filter(viewable_face_count__gt=0).order_by("name")

return queryset

@extend_schema(
Expand Down

0 comments on commit 837caeb

Please sign in to comment.