fix: ship persistent bgp ai briefs and optimize bgp queries

This commit is contained in:
rayd1o
2026-04-10 00:33:01 +08:00
parent ed898aef9c
commit 83839b8b11
21 changed files with 1996 additions and 557 deletions

View File

@@ -224,3 +224,18 @@ class BaseCollector:
- Dependency injection for testability
- Feature flags for incomplete features
- Use config files for environment-specific settings
---
## Query Performance - MANDATORY
- **NEVER** load whole tables into Python just to do filtering, pagination, counting, dedupe, or summary aggregation
- Filters, sorting, pagination, `count`, `distinct`, and grouped statistics **MUST** be pushed down to the database whenever the ORM/query builder can express them
- Summary/dashboard endpoints should prefer dedicated aggregate queries or aggregate endpoints, not multiple full-table scans
- For hot paths, avoid selecting large JSON/text payload columns unless the response really needs them
- If an endpoint returns a list, default to database-side pagination instead of `scalars().all()` followed by Python slicing
- When you suspect a query is slow, first check for:
- full-table ORM loads
- Python-side post-filtering
- repeated summary queries that can be merged
- repeated per-request recomputation that should be cached or aggregated once