Skip to content

Commit 53179da

Browse files
authored
feat(core): order projects by recent activity (anomalyco#50790)
1 parent bab26d6 commit 53179da

22 files changed

Lines changed: 180 additions & 40 deletions

File tree

‎packages/app/src/runtime/server/global-sync/utils.test.ts‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ describe("normalizeProviderList", () => {
9393

9494
describe("normalizeProjectInfo", () => {
9595
test("keeps the project VCS backend", () => {
96-
const project = { id: "prj", canonical: "/repo", time: { created: 1, updated: 1 }, sandboxes: [] }
96+
const project = { id: "prj", canonical: "/repo", time: { created: 1, updated: 1, active: 1 }, sandboxes: [] }
9797
expect(normalizeProjectInfo({ ...project, vcs: "git" } as Project).vcs).toBe("git")
9898
expect(normalizeProjectInfo({ ...project, vcs: "hg" } as Project).vcs).toBe("hg")
9999
expect(normalizeProjectInfo(project as Project).vcs).toBeUndefined()
@@ -124,7 +124,7 @@ describe("updateProjectInfo", () => {
124124
canonical: "/repo",
125125
name: "Repo",
126126
icon: { color: "purple" },
127-
time: { created: 1, updated: 2 },
127+
time: { created: 1, updated: 2, active: 2 },
128128
sandboxes: ["/repo-sandbox"],
129129
} satisfies Project
130130

‎packages/app/src/settings/servers/inventory.test.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ test("settings project inventory reads metadata without acquiring directory stor
2424
name: `Project ${index}`,
2525
icon: { color: "orange" },
2626
commands: { start: "bun install" },
27-
time: { created: 1, updated: 1 },
27+
time: { created: 1, updated: 1, active: 1 },
2828
sandboxes: [],
2929
worktrees: [],
3030
}))

‎packages/app/src/workspaces/inventory.test.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ describe("withWorktreeInventory", () => {
107107
id: "project",
108108
canonical: "/repo",
109109
name: "Before",
110-
time: { created: 1, updated: 1 },
110+
time: { created: 1, updated: 1, active: 1 },
111111
sandboxes: [],
112112
}
113113

‎packages/client/src/promise/generated/types.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -296,7 +296,7 @@ export type ProjectIcon = { url?: string; override?: string; color?: string }
296296

297297
export type ProjectCommands = { start?: string }
298298

299-
export type ProjectTime = { created: number; updated: number }
299+
export type ProjectTime = { created: number; updated: number; active: number }
300300

301301
export type PermissionSource = { type: "tool"; messageID: string; id: string }
302302

‎packages/client/src/solid/data.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1788,7 +1788,7 @@ export function createData(config: CreateDataInput) {
17881788
},
17891789
project: {
17901790
list() {
1791-
return Object.values(store.project.info).toSorted((a, b) => b.time.updated - a.time.updated)
1791+
return Object.values(store.project.info).toSorted((a, b) => b.time.active - a.time.active)
17921792
},
17931793
get(projectID: string) {
17941794
return store.project.info[projectID]

‎packages/core/schema.json‎

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
{
22
"version": "7",
33
"dialect": "sqlite",
4-
"id": "be60f352-8da1-40e1-8d70-dc41121cfbc5",
5-
"prevIds": ["3fb67508-0196-4bae-b2bd-c08ece7583fd"],
4+
"id": "e98619ef-c334-45e3-8c48-9932ed1ef290",
5+
"prevIds": ["be60f352-8da1-40e1-8d70-dc41121cfbc5"],
66
"ddl": [
77
{
88
"name": "account_state",
@@ -700,6 +700,16 @@
700700
"entityType": "columns",
701701
"table": "project"
702702
},
703+
{
704+
"type": "integer",
705+
"notNull": true,
706+
"autoincrement": false,
707+
"default": "0",
708+
"generated": null,
709+
"name": "time_active",
710+
"entityType": "columns",
711+
"table": "project"
712+
},
703713
{
704714
"type": "text",
705715
"notNull": true,

‎packages/core/src/database/migration.gen.ts‎

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import { Effect } from "effect"
2+
import type { DatabaseMigration } from "../migration.js"
3+
4+
const migration: DatabaseMigration.Migration = {
5+
id: "20260923013825_project_time_active",
6+
up(tx) {
7+
return Effect.gen(function* () {
8+
yield* tx.run(`ALTER TABLE \`project\` ADD \`time_active\` integer DEFAULT 0 NOT NULL;`)
9+
yield* tx.run(`UPDATE \`project\` SET \`time_active\` = \`time_updated\`;`)
10+
})
11+
},
12+
}
13+
14+
export default migration

‎packages/core/src/database/schema.gen.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,7 @@ const schema: Omit<DatabaseMigration.Migration, "id"> = {
110110
\`time_created\` integer NOT NULL,
111111
\`time_updated\` integer NOT NULL,
112112
\`time_initialized\` integer,
113+
\`time_active\` integer DEFAULT 0 NOT NULL,
113114
\`sandboxes\` text NOT NULL,
114115
\`commands\` text
115116
);

‎packages/core/src/database/v1-migration.bun.ts‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -523,8 +523,8 @@ export function run(options: Options = {}): Effect.Effect<RunResult, never, Data
523523
if (!(yield* hasLegacySessions(db))) return { status: "completed" as const }
524524
const now = Date.now()
525525
yield* db.run(sql`
526-
INSERT OR IGNORE INTO project (id, worktree, time_created, time_updated, sandboxes)
527-
VALUES (${Project.ID.global}, ${path.parse(global.data).root}, ${now}, ${now}, '[]')
526+
INSERT OR IGNORE INTO project (id, worktree, time_created, time_updated, time_active, sandboxes)
527+
VALUES (${Project.ID.global}, ${path.parse(global.data).root}, ${now}, ${now}, ${now}, '[]')
528528
`)
529529
if (state === undefined)
530530
yield* db
@@ -753,11 +753,11 @@ function importNextDatabase(
753753
yield* tx.run(sql`
754754
INSERT OR IGNORE INTO project (
755755
id, worktree, vcs, name, icon_url, icon_url_override, icon_color,
756-
time_created, time_updated, time_initialized, sandboxes, commands
756+
time_created, time_updated, time_initialized, time_active, sandboxes, commands
757757
) VALUES (
758758
${project.id}, ${project.worktree}, ${project.vcs}, ${project.name}, ${project.icon_url},
759759
${project.icon_url_override}, ${project.icon_color}, ${project.time_created}, ${project.time_updated},
760-
${project.time_initialized}, ${project.sandboxes}, ${project.commands}
760+
${project.time_initialized}, ${project.time_updated}, ${project.sandboxes}, ${project.commands}
761761
)
762762
`)
763763
const existing = yield* tx

0 commit comments

Comments
 (0)