Skip to content

Commit

Permalink
Fix search vector update
Browse files Browse the repository at this point in the history
Add output fields and better null caching
  • Loading branch information
matti-lamppu committed Dec 4, 2024
1 parent 8d8568f commit aa901ce
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions tilavarauspalvelu/models/reservation_unit/queryset.py
Original file line number Diff line number Diff line change
Expand Up @@ -156,42 +156,51 @@ def update_search_vectors(self, reservation_unit_pk: int | None = None) -> None:
models.F(f"description_{lang}"),
#
# Additional search terms
models.Value(" ".join(term for term in reservation_unit.search_terms)),
models.Value(
" ".join(term for term in reservation_unit.search_terms),
output_field=models.CharField(),
),
#
# Joins are not allowed in search vectors, so we compute them as values beforehand.
models.Value(
getattr(reservation_unit.unit, f"name_{lang}", ""),
getattr(reservation_unit.unit, f"name_{lang}", "") or "",
output_field=models.CharField(),
),
models.Value(
getattr(reservation_unit.reservation_unit_type, f"name_{lang}", ""),
getattr(reservation_unit.reservation_unit_type, f"name_{lang}", "") or "",
output_field=models.CharField(),
),
models.Value(
" ".join(
name
for inst in reservation_unit.spaces.all()
if (name := getattr(inst, f"name_{lang}", ""))
),
output_field=models.CharField(),
),
models.Value(
" ".join(
name
for inst in reservation_unit.resources.all()
if (name := getattr(inst, f"name_{lang}", ""))
),
output_field=models.CharField(),
),
models.Value(
" ".join(
name
for inst in reservation_unit.purposes.all()
if (name := getattr(inst, f"name_{lang}", ""))
),
output_field=models.CharField(),
),
models.Value(
" ".join(
name
for inst in reservation_unit.equipments.all()
if (name := getattr(inst, f"name_{lang}", ""))
),
output_field=models.CharField(),
),
#
config=config,
Expand Down

0 comments on commit aa901ce

Please sign in to comment.