perf: share attribution computation across PostgreSQL dimensions - #4538
dongwonmoon wants to merge 2 commits into
Conversation
|
@dongwonmoon is attempting to deploy a commit to the Umami Software Team on Vercel. A member of the Team first needs to authorize it. |
Greptile SummaryThis PR consolidates PostgreSQL attribution reporting from eight sequential statements into one statement that shares the conversion and attribution-model CTEs.
Confidence Score: 4/5The PR appears safe to merge, with a non-blocking correction recommended to guarantee ranked array ordering. The shared CTE construction preserves the supported filters, joins, models, and totals behavior, but the new JSON aggregation leaves dimension array ordering dependent on execution order rather than expressing it in the aggregate. Files Needing Attention: src/queries/sql/attribution/getAttribution.ts
|
| Filename | Overview |
|---|---|
| src/queries/sql/attribution/getAttribution.ts | Replaces eight PostgreSQL queries with shared CTEs and one JSON-producing statement; aggregate ordering is not explicit. |
| src/queries/sql/attribution/getAttribution.test.ts | Updates mocked PostgreSQL expectations for one raw query and the combined result object. |
Flowchart
%%{init: {'theme': 'neutral'}}%%
flowchart LR
P[Attribution parameters] --> E[events CTE]
E --> M[shared model CTE]
M --> R[referrer CTE]
M --> A[paidAds CTE]
M --> U[five UTM CTEs]
P --> T[total CTE]
R --> J[json_build_object]
A --> J
U --> J
T --> J
J --> O[AttributionResult]
Reviews (1): Last reviewed commit: "perf: share PostgreSQL attribution compu..." | Re-trigger Greptile
Co-authored-by: greptile-apps[bot] <165735046+greptile-apps[bot]@users.noreply.github.com>
Summary
The PostgreSQL attribution report repeats conversion and first/last-touch computation for each dimension, issuing eight sequential queries including totals.
This change shares that computation through CTEs and returns the seven dimension results and totals in one SQL statement. It retains the existing filters, attribution models, per-dimension grouping and top-20 limits. ClickHouse is unchanged; no cache or configuration is added.
Verification
On fixed synthetic data, an earlier 30-day SQL prototype comparison reduced median time from 228 to 97 ms for first-click and 217 to 90 ms for last-click. These are local prototype measurements, not production results or HTTP timings of this build.
Behavior differences and limitations
The report now reads one statement snapshot instead of eight separate snapshots. If data is committed while the report is being calculated, its result can differ from the previous implementation; an interleaved-write check confirmed this distinction.
The existing rankings have no secondary tie-breaker. Selected rows and array order matched in the tested cases, but this does not guarantee identical tied selections under every execution plan. Production-scale memory usage has not been measured.
Need help on this PR? Tag
@codesmith-botwith what you need. Autofix is disabled.