Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions packages/core/src/session/stats.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ export const get = Effect.fn("SessionStats.get")(function* (input: Input = {}) {
const db = (yield* Database.Service).db
const to = input.to ?? Date.now()
if (input.from !== undefined && input.from >= to) return yield* new InvalidRangeError({ from: input.from, to })
const project = input.projectID === undefined ? sql`` : sql`AND session.project_id = ${input.projectID}`
const project = input.projectID ? sql`AND session.project_id = ${input.projectID}` : sql``
const from =
input.from ??
(yield* db
Expand Down Expand Up @@ -282,7 +282,7 @@ export const get = Effect.fn("SessionStats.get")(function* (input: Input = {}) {
const ids = yield* db
.select({ id: SessionTable.id })
.from(SessionTable)
.where(input.projectID === undefined ? undefined : eq(SessionTable.project_id, input.projectID))
.where(input.projectID ? eq(SessionTable.project_id, input.projectID) : undefined)
.all()
.pipe(Effect.orDie)
const events = (yield* Effect.forEach(
Expand Down
11 changes: 11 additions & 0 deletions packages/core/test/session-stats.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,17 @@ describe("SessionStats", () => {
const project = yield* SessionStats.get({ projectID, timezone: "UTC", tools: "none" })
expect(DateTime.toEpochMillis(project.range.from)).toBe(Date.UTC(2025, 11, 30, 10))

// An empty project filter behaves like an omitted one. No explicit `from`,
// so this also covers the derived-range query that shares the same filter.
const unfiltered = yield* SessionStats.get({ to: Date.UTC(2026, 1, 1), timezone: "UTC", tools: "none" })
const emptyProject = yield* SessionStats.get({
to: Date.UTC(2026, 1, 1),
projectID: Project.ID.make(""),
timezone: "UTC",
tools: "none",
})
expect(emptyProject).toEqual(unfiltered)

const error = yield* Effect.flip(
SessionStats.get({ from: Date.UTC(2026, 1, 1), to: Date.UTC(2026, 0, 1), tools: "none" }),
)
Expand Down
Loading