diff --git a/keyserver/src/cron/metrics.js b/keyserver/src/cron/metrics.js --- a/keyserver/src/cron/metrics.js +++ b/keyserver/src/cron/metrics.js @@ -17,6 +17,7 @@ } const oneDayAgo = Date.now() - millisecondsPerDay; + const oneWeekAgo = Date.now() - millisecondsPerDay * 7; const thirtyDaysAgo = Date.now() - millisecondsPerDay * 30; const [ dailyActives, @@ -26,6 +27,9 @@ lastWeekThreeWeekRetention, lastDayRetentionSinceLaunch, lastWeekRetentionSinceLaunch, + dailyUniqueMessageAuthors, + weeklyUniqueMessageAuthors, + monthlyUniqueMessageAuthors, ] = await Promise.all([ getActiveCountSince(oneDayAgo), getActiveCountSince(thirtyDaysAgo), @@ -34,6 +38,9 @@ getRetention(21, 14, 7), getRetentionSinceLaunch(1), getRetentionSinceLaunch(7), + getUniqueMessageAuthorCountSince(oneDayAgo), + getUniqueMessageAuthorCountSince(oneWeekAgo), + getUniqueMessageAuthorCountSince(thirtyDaysAgo), ]); const metrics = { @@ -44,6 +51,9 @@ 'D21 (weekly)': lastWeekThreeWeekRetention, 'daily retention since launch': lastDayRetentionSinceLaunch, 'weekly retention since launch': lastWeekRetentionSinceLaunch, + 'unique message authors (daily)': dailyUniqueMessageAuthors, + 'unique message authors (weekly)': weeklyUniqueMessageAuthors, + 'unique message authors (monthly)': monthlyUniqueMessageAuthors, }; const today = new Date().toLocaleString('default', { day: 'numeric', @@ -74,7 +84,7 @@ SELECT COUNT(DISTINCT u.id) AS count FROM users u LEFT JOIN cookies c ON c.user = u.id - WHERE last_used IS NOT NULL AND last_used > ${time} + WHERE last_used IS NOT NULL AND last_used >= ${time} `); const [row] = result; return row.count; @@ -105,7 +115,7 @@ const oneDayAgo = Date.now() - millisecondsPerDay * activityCheckDaysAgo; const retainedCount = result.filter( - ({ lastUsed }) => lastUsed > oneDayAgo, + ({ lastUsed }) => lastUsed >= oneDayAgo, ).length; return { retainedCount, totalCount }; @@ -144,4 +154,14 @@ return totalRetentionResults; } +async function getUniqueMessageAuthorCountSince(time: number): Promise { + const [result] = await dbQuery(SQL` + SELECT COUNT(DISTINCT user) AS count + FROM messages + WHERE time >= ${time} + `); + const [row] = result; + return row.count; +} + export { postMetrics };