Skip to content
Open
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/livekit-cf/src/do/livestore-client/do.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ export class LiveStoreClientDO
await this.getStore();
// // Make sure to only subscribe once
// if (this.storeSubscription === undefined) {
// this.storeSubscription = store.subscribe(catalog.queries.tasks$, {
// this.storeSubscription = store.subscribe(catalog.queries.allTasks$, {
// // FIXME(meng): implement this with store.events stream when it's ready
// onUpdate: (tasks) => this.onTasksUpdateThrottled.call(tasks),
// });
Expand All @@ -126,7 +126,7 @@ export class LiveStoreClientDO

private onTasksUpdate = async (force?: boolean) => {
const store = await this.getStore();
const tasks = store.query(catalog.queries.tasks$);
const tasks = store.query(catalog.queries.allTasks$);
const oneMinuteAgo = moment().subtract(1, "minute");

const updatedTasks = tasks.filter(
Expand Down
12 changes: 12 additions & 0 deletions packages/livekit/src/livestore/default-queries.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { describe, expect, it } from "vitest";
import { allTasks$, tasks$ } from "./default-queries";

describe("task queries", () => {
it("keeps the task-list query scoped to root tasks", () => {
expect(tasks$.hash).toContain('.where("parentId", "=", null)');
});

it("does not exclude child tasks from the all-tasks query", () => {
expect(allTasks$.hash).not.toContain("parentId");
});
});
7 changes: 7 additions & 0 deletions packages/livekit/src/livestore/default-queries.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,13 @@ export const tasks$ = queryDb(
},
);

export const allTasks$ = queryDb(
() => tables.tasks.orderBy("createdAt", "desc"),
{
label: "allTasks",
},
);

export const makeSubTaskQuery = (taskId: string) =>
queryDb(() => tables.tasks.where("parentId", "=", taskId), {
label: "subTasks",
Expand Down