Skip to content

Commit

Permalink
Do not reuse QuerySet
Browse files Browse the repository at this point in the history
  • Loading branch information
derneuere authored Jun 17, 2023
1 parent aa7188e commit 565238e
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions api/api_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -173,14 +173,16 @@ def get_search_term_examples(user):
"for file path or file name",
]

pp = Photo.objects.filter(owner=user).exclude(captions_json={})[:1000]
possible_ids = list(pp.values_list("image_hash", flat=True))
possible_ids = list(Photo.objects.filter(owner=user).exclude(captions_json={})[:1000].values_list("image_hash", flat=True))
if len(possible_ids) > 99:
possible_ids = random.choices(possible_ids, k=100)
logger.info(f"{len(possible_ids)} possible ids")
try:
samples = (
pp.filter(image_hash__in=possible_ids)
Photo.objects
.filter(owner=user)
.exclude(captions_json={})
.filter(image_hash__in=possible_ids)
.prefetch_related("faces")
.prefetch_related("faces__person")
.all()
Expand Down

0 comments on commit 565238e

Please sign in to comment.