Motivation
Right now, searching for a specific page/event/poi requires two sql queries, one for finding the matching translations and one to convert the object translations into the objects themselves. This could be done in one sql query.
Additional Context
#929 (comment):
In view of our performance problems, I even have a completely new suggestion: instead of implementing the search as a model method, we could define the search function as a QuerySet method which can be chained to other database filters and thus reducing the amount of queries used:
class EventQuerySet(models.QuerySet):
def search(self, language_slug, query):
return self.filter(
translations__language__slug=language_slug,
translations__title__icontains=query,
)
class Event(models.Model):
...
objects = models.Manager.from_queryset(EventQuerySet)()
...
Then, it could be used e.g. like this:
events = region.events.filter(archived=self.archived)
...
query = event_filter_form.cleaned_data["query"]
if query:
events = events.search(language_slug, query)
and in the end, only one sql would be performed, since querysets are lazy...
Motivation
Right now, searching for a specific page/event/poi requires two sql queries, one for finding the matching translations and one to convert the object translations into the objects themselves. This could be done in one sql query.
Additional Context
#929 (comment):
In view of our performance problems, I even have a completely new suggestion: instead of implementing the search as a model method, we could define the search function as a QuerySet method which can be chained to other database filters and thus reducing the amount of queries used:
Then, it could be used e.g. like this:
and in the end, only one sql would be performed, since querysets are lazy...