Fix nearest hubs fallback when source missing
All checks were successful
Build Docker Image / build (push) Successful in 1m32s

This commit is contained in:
Ruslan Bakiev
2026-02-05 20:10:11 +07:00
parent 09324bb25e
commit 443dc7fa5d

View File

@@ -1474,9 +1474,9 @@ class Query(graphene.ObjectType):
nodes_col = db.collection('nodes')
start = nodes_col.get(source_uuid)
if not start:
logger.warning("Source node %s not found for nearest hubs", source_uuid)
return []
logger.warning("Source node %s not found for nearest hubs, falling back to radius search", source_uuid)
source_uuid = None
else:
def is_target_hub(doc):
if doc.get('_key') == source_uuid:
return False
@@ -1626,6 +1626,46 @@ class Query(graphene.ObjectType):
db = get_db()
ensure_graph()
# If hub_uuid + product_uuid provided, use graph search to return only offers with routes.
if hub_uuid and product_uuid:
try:
nodes_col = db.collection('nodes')
expanded_limit = max(limit * 5, limit)
route_options = Query.resolve_offers_by_hub(
Query, info, hub_uuid, product_uuid, expanded_limit
)
offers = []
for option in route_options or []:
if not option.routes:
continue
node = nodes_col.get(option.source_uuid)
if not node:
continue
offers.append(OfferWithRouteType(
uuid=node['_key'],
product_uuid=node.get('product_uuid'),
product_name=node.get('product_name'),
supplier_uuid=node.get('supplier_uuid'),
supplier_name=node.get('supplier_name'),
latitude=node.get('latitude'),
longitude=node.get('longitude'),
country=node.get('country'),
country_code=node.get('country_code'),
price_per_unit=node.get('price_per_unit'),
currency=node.get('currency'),
quantity=node.get('quantity'),
unit=node.get('unit'),
distance_km=option.distance_km,
routes=option.routes,
))
if len(offers) >= limit:
break
logger.info("Found %d offers by graph for hub %s", len(offers), hub_uuid)
return offers
except Exception as e:
logger.error("Error finding offers by hub %s: %s", hub_uuid, e)
return []
aql = """
FOR offer IN nodes
FILTER offer.node_type == 'offer'