From c609e79ddea18f5ece67bdabc80cecd7c68ab172 Mon Sep 17 00:00:00 2001 From: Griatch Date: Sat, 14 Feb 2026 23:54:24 +0100 Subject: [PATCH] CI: Try to reduce PostgreSQL overhead on XYZgrid multiple table merge (slowing Postgres CI runs) --- evennia/contrib/grid/xyzgrid/xyzroom.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/evennia/contrib/grid/xyzgrid/xyzroom.py b/evennia/contrib/grid/xyzgrid/xyzroom.py index 21de4aa874..4341cf8cd6 100644 --- a/evennia/contrib/grid/xyzgrid/xyzroom.py +++ b/evennia/contrib/grid/xyzgrid/xyzroom.py @@ -73,6 +73,7 @@ class XYZManager(ObjectManager): if z == wildcard else Q(db_tags__db_key__iexact=str(z), db_tags__db_category=MAP_Z_TAG_CATEGORY) ) + .distinct() ) def get_xyz(self, xyz=(0, 0, "map"), **kwargs): @@ -97,9 +98,12 @@ class XYZManager(ObjectManager): """ # filter by tags, then figure out of we got a single match or not query = self.filter_xyz(xyz=xyz, **kwargs) - ncount = query.count() + # Avoid expensive count() on multi-join tag queries; we only need to + # know if there are 0, 1 or more than 1 unique matches. + matches = list(query[:2]) + ncount = len(matches) if ncount == 1: - return query.first() + return matches[0] # error - mimic default get() behavior but with a little more info x, y, z = xyz @@ -184,6 +188,7 @@ class XYZExitManager(XYZManager): db_tags__db_key__iexact=str(zdest), db_tags__db_category=MAP_ZDEST_TAG_CATEGORY ) ) + .distinct() ) def get_xyz_exit(self, xyz=(0, 0, "map"), xyz_destination=(0, 0, "map"), **kwargs): @@ -230,6 +235,7 @@ class XYZExitManager(XYZManager): .filter( db_tags__db_key__iexact=str(zdest), db_tags__db_category=MAP_ZDEST_TAG_CATEGORY ) + .distinct() .get(**kwargs) ) except self.model.DoesNotExist: