Strategic Action Plan: OMGT Performance Stabilization
This plan separates the mitigation of performance issues into three distinct streams: Advanced Search Optimization (Stream 1), Data Export Optimization (Stream 2), and UX & Guardrails (Stream 3).
Stream 1: Advanced Search Optimization
Goal
Restore reliability and paging efficiency to the search results by offloading filtering logic to the SQL engine.
Proposed Changes
OrderAdvancedSearchQueryBuilder.cs
- Mitigation A (Postcode Ranges):
- Refactor
FinaliseQueryto eliminate multiple database roundtrips. - Implement a single LINQ expression combining all ranges.
- Refactor
- Mitigation B (Query Complexity):
- Audit and remove manual
.Join()calls that are already handled by the SQL view. - Switch from Joins to
.Any()predicates for relationship filtering.
- Audit and remove manual
- Mitigation E (Round 3: Combinatorial Explosion):
- Scale: Resolve the risk of the ~30 filter categories and 1200-line DTO.
- Query Pruning: Mandatory logic to ensure unused categories do not add Join overhead to the SQL execution plan.
- Mitigation F (Structural Debt):
- Plan extraction of filter groups into Strategy classes to break down the "God Class" (5,763 LOC).
Stream 2: Data Export Optimization
Goal
Eliminate the N+1 Query problem during export generation by eagerly loading related data, while maintaining the flexibility of the template engine.
Proposed Changes
MassActionHandler.cs
- Mitigation C (Data Access - N+1 fix):
- Dynamic Prefetching: Analyze the export template columns to identify required relationships (e.g.,
Customer,OrderHeader,Payments). - Batch Loader: Before the row loop, executing a single query with necessary
.Include()clauses (or multiple batch queries) to hydrate the entities. - Rationale: Replacing 1000+ DB hits with a single query will offer far greater returns than optimizing CPU cycles.
- Dynamic Prefetching: Analyze the export template columns to identify required relationships (e.g.,
- Mitigation D (Memory Allocation):
- Optimize the loop in
ExportExcelto reduce the creation of intermediate objects.
- Optimize the loop in
Stream 3: UX & Guardrails (Strategic Response)
Goal
Reduce the "Execution Plan Poisoning" risk by guiding user behavior and simplifying the interface based on real usage.
Proposed Changes
- UX Analytics Implementation:
- Analyze
SavedSearchpatterns and implement telemetry to identify the "Essential 5" filter categories. - Reference: Search_Usage_Analytics.md
- Analyze
- Complexity Budget:
- Implement a frontend/backend warning if a user selects more than 5 high-impact filter categories simultaneously.
- "Advanced" View Toggle:
- Hide edge-case categories (e.g., PEC, Compliance) behind an "Advanced" section to prevent accidental complexity spikes.
Verification Plan
1. Functional Verification
- Re-run the manual "Rossi" search test via browser.
- Verify result counts match exactly between Legacy and Optimized paths.
2. Performance Verification
- Search: Target response time < 3s for baseline searches.
- Export: Target generation time < 10s for 1000 orders.