Fix nearest hubs fallback when source missing
All checks were successful
Build Docker Image / build (push) Successful in 1m32s
All checks were successful
Build Docker Image / build (push) Successful in 1m32s
This commit is contained in:
@@ -1474,9 +1474,9 @@ class Query(graphene.ObjectType):
|
|||||||
nodes_col = db.collection('nodes')
|
nodes_col = db.collection('nodes')
|
||||||
start = nodes_col.get(source_uuid)
|
start = nodes_col.get(source_uuid)
|
||||||
if not start:
|
if not start:
|
||||||
logger.warning("Source node %s not found for nearest hubs", source_uuid)
|
logger.warning("Source node %s not found for nearest hubs, falling back to radius search", source_uuid)
|
||||||
return []
|
source_uuid = None
|
||||||
|
else:
|
||||||
def is_target_hub(doc):
|
def is_target_hub(doc):
|
||||||
if doc.get('_key') == source_uuid:
|
if doc.get('_key') == source_uuid:
|
||||||
return False
|
return False
|
||||||
@@ -1626,6 +1626,46 @@ class Query(graphene.ObjectType):
|
|||||||
db = get_db()
|
db = get_db()
|
||||||
ensure_graph()
|
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 = """
|
aql = """
|
||||||
FOR offer IN nodes
|
FOR offer IN nodes
|
||||||
FILTER offer.node_type == 'offer'
|
FILTER offer.node_type == 'offer'
|
||||||
|
|||||||
Reference in New Issue
Block a user