Commit 83ec5be7 authored by Serge S. Koval's avatar Serge S. Koval

Ignore eagerloaded relations when building SQL search/filter query

parent f20de416
......@@ -736,15 +736,23 @@ class ModelView(BaseModelView):
query = self.get_query()
count_query = self.get_count_query()
# Ignore eager-loaded relations (prevent unnecessary joins)
# TODO: Separate join detection for query and count query?
if hasattr(query, '_join_entities'):
for entity in query._join_entities:
for table in entity.tables:
joins.add(table.name)
# Apply search criteria
if self._search_supported and search:
# Apply search-related joins
if self._search_joins:
for table in self._search_joins:
query = query.join(table)
count_query = count_query.join(table)
if table.name not in joins:
query = query.join(table)
count_query = count_query.join(table)
joins.add(table.name)
joins.add(table.name)
# Apply terms
terms = search.split(' ')
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment