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
FROM documents WHERE ${EVENTS_WHERE} AND json_extract(data,'$.event_type')='error_occurred'
146
147
GROUP BY err, version ORDER BY count DESC LIMIT 25`
147
148
).all(),
148
-
// 11. Top collections from project_snapshot (aggregate doc counts across installations)
149
+
// 11. Top collections from project_snapshot — latest snapshot per installation to avoid boot-count inflation
149
150
db.prepare(
150
-
`SELECT key AS collection, SUM(CAST(value AS INTEGER)) AS total_docs, COUNT(DISTINCT json_extract(data,'$.properties.installation_id')) AS installations
151
-
FROM documents, json_each(json(json_extract(data,'$.properties.collection_counts')))
152
-
WHERE ${EVENTS_WHERE} AND json_extract(data,'$.event_type')='project_snapshot'
151
+
`WITH latest AS (
152
+
SELECT json_extract(data,'$.properties.installation_id') AS installation_id,
153
+
json_extract(data,'$.properties.collection_counts') AS counts_json
154
+
FROM documents
155
+
WHERE ${EVENTS_WHERE} AND json_extract(data,'$.event_type')='project_snapshot'
156
+
GROUP BY json_extract(data,'$.properties.installation_id')
157
+
HAVING created_at = MAX(created_at)
158
+
)
159
+
SELECT key AS collection,
160
+
SUM(CAST(value AS INTEGER)) AS total_docs,
161
+
COUNT(DISTINCT installation_id) AS installations
162
+
FROM latest, json_each(json(counts_json))
153
163
GROUP BY key ORDER BY total_docs DESC LIMIT 20`
154
164
).all(),
155
-
// 12. Top plugins from project_snapshot (count appearances across installations)
165
+
// 12. Top plugins from project_snapshot — latest snapshot per installation
156
166
db.prepare(
157
-
`SELECT value AS plugin, COUNT(DISTINCT json_extract(data,'$.properties.installation_id')) AS installations
158
-
FROM documents, json_each(json(json_extract(data,'$.properties.active_plugins')))
159
-
WHERE ${EVENTS_WHERE} AND json_extract(data,'$.event_type')='project_snapshot'
167
+
`WITH latest AS (
168
+
SELECT json_extract(data,'$.properties.installation_id') AS installation_id,
169
+
json_extract(data,'$.properties.active_plugins') AS plugins_json
170
+
FROM documents
171
+
WHERE ${EVENTS_WHERE} AND json_extract(data,'$.event_type')='project_snapshot'
172
+
GROUP BY json_extract(data,'$.properties.installation_id')
173
+
HAVING created_at = MAX(created_at)
174
+
)
175
+
SELECT value AS plugin, COUNT(DISTINCT installation_id) AS installations
176
+
FROM latest, json_each(json(plugins_json))
160
177
GROUP BY value ORDER BY installations DESC LIMIT 20`
161
178
).all(),
162
179
// 13. Field type histogram aggregated across all snapshots
0 commit comments