You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
* [front/pages/api/w/[wId]] - refactor: optimize active user analytics query
- Simplified and optimized the query for calculating active user counts and growth percentages
- Replaced multiple common table expressions with a more efficient single CTE approach
- Removed unnecessary group by and having clauses to streamline the query execution
- Improved performance by reducing the complexity of conditional counting within the query
* [api] - fix: correct workspace analytics query parameters and growth percentage calculation
- Replace hardcoded workspace identifier with dynamic parameter binding in SQL query for analytics
- Multiply month-over-month and week-over-week growth percentages by 100 for accurate representation
COALESCE(MAX(CASE WHEN period = 'last_7_days' THEN active_users END), 0) AS "last_7_days_active_users",
129
-
COALESCE(MAX(CASE WHEN period IN ('last_30_days', 'last_7_days', 'previous_7_days') THEN active_users END), 0) AS "last_30_days_active_users",
130
-
(COALESCE(MAX(CASE WHEN period = 'last_7_days' THEN active_users END), 0) - COALESCE(MAX(CASE WHEN period = 'previous_7_days' THEN active_users END), 0))::FLOAT
131
-
/ GREATEST(COALESCE(MAX(CASE WHEN period = 'previous_7_days' THEN active_users END), 1), 1) * 100 AS "wow_growth_pct",
132
-
(COALESCE(MAX(CASE WHEN period IN ('last_30_days', 'last_7_days', 'previous_7_days') THEN active_users END), 0) - COALESCE(MAX(CASE WHEN period = 'previous_30_days' THEN active_users END), 0))::FLOAT
133
-
/ GREATEST(COALESCE(MAX(CASE WHEN period = 'previous_30_days' THEN active_users END), 1), 1) * 100 AS "mom_growth_pct"
134
-
FROM aggregated_counts
135
-
)
136
-
SELECT
137
-
"last_7_days_active_users",
138
-
ROUND(wow_growth_pct::Decimal, 2) AS "wow_growth_pct",
139
-
"last_30_days_active_users",
140
-
ROUND(mom_growth_pct::Decimal, 2) AS "mom_growth_pct"
141
-
FROM growth_calculations;
142
-
`,
167
+
"nb_active_users_last_7_days",
168
+
"wow_growth_pct",
169
+
"nb_active_users_last_30_days",
170
+
"mom_growth_pct"
171
+
FROM
172
+
calculations;
173
+
`,
143
174
{
144
175
replacements: {
145
176
wId,
146
-
messageCountThreshold: 1,
147
177
},
148
178
type: QueryTypes.SELECT,
149
179
}
@@ -210,11 +240,11 @@ async function getAnalytics(
0 commit comments