feat(server): skip cleanup for stale workspace (#13418)

fix AI-408

<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->
## Summary by CodeRabbit

* **New Features**
* Added a new field to workspaces to track the last time embeddings were
checked.
* Cleanup jobs for workspace embeddings now skip workspaces that haven't
changed in over 30 days or have no embeddings, improving efficiency.
* Cleanup jobs are now automatically triggered when a workspace is
updated.

* **Improvements**
* Enhanced workspace selection for cleanup and indexing tasks to use
more precise filters and batching.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->
This commit is contained in:
DarkSky
2025-08-06 16:11:50 +08:00
committed by GitHub
parent 713f926247
commit 9677bdf50d
6 changed files with 83 additions and 31 deletions
+12 -10
View File
@@ -111,17 +111,18 @@ model VerificationToken {
model Workspace {
// NOTE: manually set this column type to identity in migration file
sid Int @unique @default(autoincrement())
id String @id @default(uuid()) @db.VarChar
public Boolean
createdAt DateTime @default(now()) @map("created_at") @db.Timestamptz(3)
sid Int @unique @default(autoincrement())
id String @id @default(uuid()) @db.VarChar
public Boolean
createdAt DateTime @default(now()) @map("created_at") @db.Timestamptz(3)
// workspace level feature flags
enableAi Boolean @default(true) @map("enable_ai")
enableUrlPreview Boolean @default(false) @map("enable_url_preview")
enableDocEmbedding Boolean @default(true) @map("enable_doc_embedding")
name String? @db.VarChar
avatarKey String? @map("avatar_key") @db.VarChar
indexed Boolean @default(false)
enableAi Boolean @default(true) @map("enable_ai")
enableUrlPreview Boolean @default(false) @map("enable_url_preview")
enableDocEmbedding Boolean @default(true) @map("enable_doc_embedding")
name String? @db.VarChar
avatarKey String? @map("avatar_key") @db.VarChar
indexed Boolean @default(false)
lastCheckEmbeddings DateTime @default("1970-01-01T00:00:00-00:00") @map("last_check_embeddings") @db.Timestamptz(3)
features WorkspaceFeature[]
docs WorkspaceDoc[]
@@ -133,6 +134,7 @@ model Workspace {
comments Comment[]
commentAttachments CommentAttachment[]
@@index([lastCheckEmbeddings])
@@map("workspaces")
}