Remove recordings feature, replay sessions directly, bump to 0.6.0
Recordings were just a thin named pointer over an already-captured session's events, so the whole separate feature (recordings table, API routes, pages, UI) is gone: any completed session can now be named and replayed directly. Replaying no longer creates a session or duplicates events of its own - it just bumps the source session's playCount/lastPlayedAt. Also renames play_sessions/playSession(s) to sessions/session(s) throughout the schema, queries, API routes, and UI for consistency, and updates the README to match the new flow. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
+12
-42
@@ -1,26 +1,19 @@
|
||||
import { sql, eq, and, ne } from "drizzle-orm";
|
||||
import { db } from "@/lib/db/client";
|
||||
import { playSessions, sessionDevices, sessionEvents, devices, recordings } from "@/lib/db/schema";
|
||||
import { sessions, sessionDevices, sessionEvents, devices } from "@/lib/db/schema";
|
||||
|
||||
export async function getSessionsSummary() {
|
||||
const [totals] = await db
|
||||
.select({
|
||||
count: sql<number>`count(*)`,
|
||||
totalDurationMs: sql<number>`coalesce(sum(${playSessions.durationMs}), 0)`,
|
||||
avgDurationMs: sql<number>`coalesce(avg(${playSessions.durationMs}), 0)`,
|
||||
totalDurationMs: sql<number>`coalesce(sum(${sessions.durationMs}), 0)`,
|
||||
avgDurationMs: sql<number>`coalesce(avg(${sessions.durationMs}), 0)`,
|
||||
// How many times sessions have been replayed - replaying itself creates no
|
||||
// session of its own, it just bumps the source session's playCount.
|
||||
totalReplays: sql<number>`coalesce(sum(${sessions.playCount}), 0)`,
|
||||
})
|
||||
.from(playSessions)
|
||||
.where(eq(playSessions.status, "completed"));
|
||||
|
||||
const byKind = await db
|
||||
.select({
|
||||
kind: playSessions.kind,
|
||||
count: sql<number>`count(*)`,
|
||||
totalDurationMs: sql<number>`coalesce(sum(${playSessions.durationMs}), 0)`,
|
||||
})
|
||||
.from(playSessions)
|
||||
.where(eq(playSessions.status, "completed"))
|
||||
.groupBy(playSessions.kind);
|
||||
.from(sessions)
|
||||
.where(eq(sessions.status, "completed"));
|
||||
|
||||
const durationPerDevice = await db
|
||||
.select({
|
||||
@@ -33,10 +26,10 @@ export async function getSessionsSummary() {
|
||||
.innerJoin(devices, eq(sessionDevices.deviceId, devices.id))
|
||||
.groupBy(devices.id);
|
||||
|
||||
return { ...totals, byKind, durationPerDevice };
|
||||
return { ...totals, durationPerDevice };
|
||||
}
|
||||
|
||||
export async function getSessionTimeline(playSessionId: number, bucketMs = 1000) {
|
||||
export async function getSessionTimeline(sessionId: number, bucketMs = 1000) {
|
||||
// Reuse the same expression object (not a `sql`bucket`` alias reference)
|
||||
// in groupBy/orderBy - drizzle doesn't emit a literal `AS bucket` that
|
||||
// SQLite's GROUP BY/ORDER BY could resolve a bare "bucket" identifier
|
||||
@@ -53,7 +46,7 @@ export async function getSessionTimeline(playSessionId: number, bucketMs = 1000)
|
||||
})
|
||||
.from(sessionEvents)
|
||||
.innerJoin(sessionDevices, eq(sessionEvents.sessionDeviceId, sessionDevices.id))
|
||||
.where(and(eq(sessionEvents.playSessionId, playSessionId), ne(sessionEvents.commandType, "stop")))
|
||||
.where(and(eq(sessionEvents.sessionId, sessionId), ne(sessionEvents.commandType, "stop")))
|
||||
.groupBy(bucket, sessionEvents.sessionDeviceId)
|
||||
.orderBy(bucket);
|
||||
}
|
||||
@@ -64,7 +57,7 @@ export async function getDeviceUsageStats() {
|
||||
deviceId: devices.id,
|
||||
displayName: devices.displayName,
|
||||
bleName: devices.bleName,
|
||||
sessionCount: sql<number>`count(distinct ${sessionDevices.playSessionId})`,
|
||||
sessionCount: sql<number>`count(distinct ${sessionDevices.sessionId})`,
|
||||
totalActiveMs: sql<number>`coalesce(sum(coalesce(${sessionDevices.disconnectedAt}, ${sessionDevices.connectedAt}) - ${sessionDevices.connectedAt}), 0)`,
|
||||
lastUsedAt: sql<number | null>`max(${sessionDevices.connectedAt})`,
|
||||
})
|
||||
@@ -84,26 +77,3 @@ export async function getDeviceCommandCounts() {
|
||||
.leftJoin(sessionEvents, eq(sessionEvents.sessionDeviceId, sessionDevices.id))
|
||||
.groupBy(devices.id);
|
||||
}
|
||||
|
||||
export async function getRecordingLibraryStats() {
|
||||
const [totals] = await db
|
||||
.select({
|
||||
count: sql<number>`count(*)`,
|
||||
avgDurationMs: sql<number>`coalesce(avg(${recordings.durationMs}), 0)`,
|
||||
totalPlayCount: sql<number>`coalesce(sum(${recordings.playCount}), 0)`,
|
||||
})
|
||||
.from(recordings);
|
||||
|
||||
const list = await db
|
||||
.select({
|
||||
id: recordings.id,
|
||||
name: recordings.name,
|
||||
durationMs: recordings.durationMs,
|
||||
playCount: recordings.playCount,
|
||||
lastPlayedAt: recordings.lastPlayedAt,
|
||||
})
|
||||
.from(recordings)
|
||||
.orderBy(sql`${recordings.playCount} desc`);
|
||||
|
||||
return { ...totals, list };
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user