Skip to content

Commit

Permalink
feat: events table type column index
Browse files Browse the repository at this point in the history
  • Loading branch information
sjaanus committed Aug 12, 2024
1 parent 8091987 commit a12a131
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 2 deletions.
7 changes: 5 additions & 2 deletions src/lib/features/events/event-store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -158,8 +158,10 @@ class EventStore implements IEventStore {
params: IEventSearchParams,
queryParams: IQueryParam[],
): Promise<number> {
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;
}
Expand Down Expand Up @@ -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) {
Expand Down
19 changes: 19 additions & 0 deletions src/migrations/20240812132633-events-type-index.js
Original file line number Diff line number Diff line change
@@ -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,
);
};

0 comments on commit a12a131

Please sign in to comment.