restrict name-only address searches early by postcode

This commit is contained in:
Sarah Hoffmann
2025-07-11 22:04:12 +02:00
parent 93ac1023f7
commit e111257644

View File

@@ -175,8 +175,7 @@ class AddressSearch(base.AbstractSearch):
sql = sql.where(t.c.country_code.in_(self.countries.values))
if self.postcodes:
if self.expected_count > 10000:
# Many results expected. Restrict by postcode.
if not self.has_address_terms or self.expected_count > 10000:
tpc = conn.t.postcode
sql = sql.where(sa.select(tpc.c.postcode)
.where(tpc.c.postcode.in_(self.postcodes.values))