New alert service
This commit is contained in:
@@ -215,6 +215,65 @@ class SalesServiceClient(BaseServiceClient):
|
||||
params=params
|
||||
)
|
||||
|
||||
async def get_sales_summary_batch(
|
||||
self,
|
||||
tenant_ids: List[str],
|
||||
start_date: date,
|
||||
end_date: date
|
||||
) -> Dict[str, Any]:
|
||||
"""
|
||||
Get sales summaries for multiple tenants in a single request.
|
||||
|
||||
Phase 2 optimization: Eliminates N+1 query patterns for enterprise dashboards.
|
||||
|
||||
Args:
|
||||
tenant_ids: List of tenant IDs to fetch
|
||||
start_date: Start date for summary range
|
||||
end_date: End date for summary range
|
||||
|
||||
Returns:
|
||||
Dict mapping tenant_id -> sales summary
|
||||
"""
|
||||
try:
|
||||
if not tenant_ids:
|
||||
return {}
|
||||
|
||||
if len(tenant_ids) > 100:
|
||||
logger.warning("Batch request exceeds max tenant limit", requested=len(tenant_ids))
|
||||
tenant_ids = tenant_ids[:100]
|
||||
|
||||
data = {
|
||||
"tenant_ids": tenant_ids,
|
||||
"start_date": start_date.isoformat(),
|
||||
"end_date": end_date.isoformat()
|
||||
}
|
||||
|
||||
result = await self.post(
|
||||
"sales/batch/sales-summary",
|
||||
data=data,
|
||||
tenant_id=tenant_ids[0] # Use first tenant for auth context
|
||||
)
|
||||
|
||||
summaries = result if isinstance(result, dict) else {}
|
||||
|
||||
logger.info(
|
||||
"Batch retrieved sales summaries",
|
||||
requested=len(tenant_ids),
|
||||
found=len(summaries),
|
||||
start_date=start_date.isoformat(),
|
||||
end_date=end_date.isoformat()
|
||||
)
|
||||
|
||||
return summaries
|
||||
|
||||
except Exception as e:
|
||||
logger.error(
|
||||
"Error batch fetching sales summaries",
|
||||
error=str(e),
|
||||
tenant_count=len(tenant_ids)
|
||||
)
|
||||
return {}
|
||||
|
||||
# ================================================================
|
||||
# DATA IMPORT
|
||||
# ================================================================
|
||||
|
||||
Reference in New Issue
Block a user