diff --git a/src/lib/features/events/event-store.ts b/src/lib/features/events/event-store.ts index bf8efaeed7da..8367b63b39d3 100644 --- a/src/lib/features/events/event-store.ts +++ b/src/lib/features/events/event-store.ts @@ -158,8 +158,10 @@ class EventStore implements IEventStore { params: IEventSearchParams, queryParams: IQueryParam[], ): Promise { - const query = this.buildSearchQuery(params, queryParams); - const count = await query.count().first(); + const query = this.buildSearchQuery(params, queryParams) + .count() + .first(); + const count = await query; if (!count) { return 0; } @@ -353,6 +355,7 @@ class EventStore implements IEventStore { .limit(Number(params.limit) ?? 100) .offset(Number(params.offset) ?? 0); + console.log(query.toQuery()); try { return (await query).map(this.rowToEvent); } catch (err) { diff --git a/src/migrations/20240812132633-events-type-index.js b/src/migrations/20240812132633-events-type-index.js new file mode 100644 index 000000000000..33b18eef021a --- /dev/null +++ b/src/migrations/20240812132633-events-type-index.js @@ -0,0 +1,19 @@ +'use strict'; + +exports.up = function (db, callback) { + db.runSql( + ` + CREATE INDEX idx_events_type ON events (type DESC); + `, + callback, + ); +}; + +exports.down = function (db, callback) { + db.runSql( + ` + DROP INDEX IF EXISTS idx_events_type; + `, + callback, + ); +};