From dd1cd1f249a5fa3ba9f5005360c7fb81d5afac48 Mon Sep 17 00:00:00 2001 From: eust-w Date: Mon, 15 Jun 2026 17:50:39 +0800 Subject: [PATCH] =?UTF-8?q?=F0=9F=A7=B9=20Add=20Mongo=20indexes=20and=20fr?= =?UTF-8?q?ontend=20formatting?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitignore | 1 + .prettierignore | 7 + .prettierrc.json | 6 + README.md | 2 + cmd/api/main.go | 4 + cmd/worker/main.go | 4 + docs/operations.md | 4 +- internal/store/mongo_indexes.go | 97 + package-lock.json | 17 + package.json | 5 +- src/App.tsx | 25 +- src/components/AIGenerateModal.tsx | 24 +- src/components/ArtifactPreviewPanel.tsx | 19 +- src/components/Logo.tsx | 36 +- src/components/Sidebar.tsx | 28 +- src/components/UserBootstrapPanel.tsx | 4 +- src/context/TimeZoneContext.tsx | 22 +- src/hooks/useAIStatus.ts | 3 +- src/index.css | 11 +- src/lib/datetime.ts | 28 +- src/main.tsx | 10 +- src/pages/Audit.tsx | 105 +- src/pages/Dashboard.tsx | 15 +- src/pages/DataAssets.tsx | 537 ++-- src/pages/DatabaseBrowser.tsx | 330 +-- src/pages/Monitoring.tsx | 269 +- src/pages/ObjectStorageBrowser.tsx | 162 +- src/pages/Operators.tsx | 333 ++- src/pages/Packages.tsx | 55 +- src/pages/ProjectDetail.tsx | 437 ++-- src/pages/Projects.tsx | 55 +- src/pages/Sampling.tsx | 120 +- src/pages/Settings.tsx | 150 +- src/pages/SourceData.tsx | 118 +- src/pages/Templates.tsx | 75 +- src/pages/Users.tsx | 51 +- src/pages/WorkflowEditor.tsx | 2317 ++++++------------ src/services/aiService.ts | 7 +- src/services/api/ai.ts | 18 +- src/services/api/data-platform.ts | 40 +- src/services/api/database.ts | 16 +- src/services/api/external-business-db.ts | 5 +- src/services/api/mongo-connections.ts | 7 +- src/services/api/monitoring.ts | 41 +- src/services/api/object-storage.ts | 49 +- src/services/api/operators.ts | 3 +- src/services/api/projects.ts | 6 +- src/services/api/settings.ts | 3 +- src/services/api/storage-connections.ts | 22 +- src/services/api/users.ts | 9 +- src/services/api/workflows.ts | 7 +- src/types.ts | 26 +- tests/frontend/data-assets.test.mjs | 5 +- tests/frontend/scan-workflows.test.mjs | 30 +- tests/frontend/storage-path-history.test.mjs | 48 +- tests/frontend/template-settings.test.mjs | 5 +- tests/frontend/templates.test.mjs | 10 +- tests/frontend/video-preview.test.mjs | 5 +- tests/frontend/workflow-canvas.test.mjs | 4 +- tests/frontend/workflow-run.test.mjs | 17 +- tests/frontend/workflow-system-env.test.mjs | 10 +- tmp/business-mongo-validation.mjs | 124 - tmp/business-mongo-validation.sh | 85 - tmp/live-real-data-acceptance.mjs | 320 --- tmp/object-storage-debug.mjs | 65 - tmp/operators-live-summary.txt | 52 - tmp/project-operator-count.png | Bin 83534 -> 0 bytes tmp/template-dblclick-edit.png | Bin 64027 -> 0 bytes tmp/templates-operator-count.png | Bin 122172 -> 0 bytes 69 files changed, 2180 insertions(+), 4345 deletions(-) create mode 100644 .prettierignore create mode 100644 .prettierrc.json create mode 100644 internal/store/mongo_indexes.go delete mode 100644 tmp/business-mongo-validation.mjs delete mode 100644 tmp/business-mongo-validation.sh delete mode 100644 tmp/live-real-data-acceptance.mjs delete mode 100644 tmp/object-storage-debug.mjs delete mode 100644 tmp/operators-live-summary.txt delete mode 100644 tmp/project-operator-count.png delete mode 100644 tmp/template-dblclick-edit.png delete mode 100644 tmp/templates-operator-count.png diff --git a/.gitignore b/.gitignore index 5a86d2a8..b4093fa2 100644 --- a/.gitignore +++ b/.gitignore @@ -2,6 +2,7 @@ node_modules/ build/ dist/ coverage/ +tmp/ .DS_Store *.log .env* diff --git a/.prettierignore b/.prettierignore new file mode 100644 index 00000000..53bd88af --- /dev/null +++ b/.prettierignore @@ -0,0 +1,7 @@ +build/ +coverage/ +dist/ +node_modules/ +tmp/ +docs/ +backend/operator-runner/ diff --git a/.prettierrc.json b/.prettierrc.json new file mode 100644 index 00000000..caa6777f --- /dev/null +++ b/.prettierrc.json @@ -0,0 +1,6 @@ +{ + "printWidth": 120, + "semi": true, + "singleQuote": false, + "trailingComma": "all" +} diff --git a/README.md b/README.md index 709b8fe4..a839ecf3 100644 --- a/README.md +++ b/README.md @@ -60,6 +60,8 @@ Drobodata is a workflow orchestration platform for embodied AI and vision pipeli ### Useful Scripts - `npm run lint`: type-check frontend and verify Go formatting +- `npm run format`: format frontend source and frontend tests with Prettier +- `npm run format:check`: check frontend formatting without writing files - `npm test`: Go unit and integration tests - `npm run build`: build frontend assets and Go binaries - `npm run verify`: lint, Go tests, Python operator-runner tests, frontend node tests, build, dependency audit, and Kubernetes manifest dry-run validation diff --git a/cmd/api/main.go b/cmd/api/main.go index 68fe2ef1..2a18ad79 100644 --- a/cmd/api/main.go +++ b/cmd/api/main.go @@ -69,6 +69,10 @@ func main() { }() dataStore := store.NewMongoStore(client.Database(cfg.MongoDB)) + if err := dataStore.EnsureIndexes(ctx); err != nil { + fmt.Printf("[api] failed to ensure mongo indexes: %v\n", err) + os.Exit(1) + } aiService := ai.NewService(cfg.AIAPIBaseURL, cfg.AIAPIKey, cfg.AIModel) handler := spaHandler(api.NewHandler(dataStore, aiService), cfg.DistDir) diff --git a/cmd/worker/main.go b/cmd/worker/main.go index a79b72c0..3d810822 100644 --- a/cmd/worker/main.go +++ b/cmd/worker/main.go @@ -44,6 +44,10 @@ func main() { }() dataStore := store.NewMongoStore(client.Database(cfg.MongoDB)) + if err := dataStore.EnsureIndexes(ctx); err != nil { + fmt.Printf("[worker] failed to ensure mongo indexes: %v\n", err) + os.Exit(1) + } runtime, err := worker.NewRuntime( dataStore, cfg.K8sNamespace, diff --git a/docs/operations.md b/docs/operations.md index f45007e7..29247028 100644 --- a/docs/operations.md +++ b/docs/operations.md @@ -41,6 +41,8 @@ - `users` - `settings` +API and worker startup both call `EnsureIndexes` on the platform MongoDB. Index creation is idempotent and covers the main lookup and dispatch paths such as run status queues, workflow/project run history, source-state checkpoints, audit queues, and singleton/settings lookups. + ## Run Lifecycle 1. frontend calls `POST /api/workflows/:id/run` @@ -60,7 +62,7 @@ Run the full verification loop: npm run verify ``` -This includes TypeScript/Go linting, Go tests, Python operator-runner tests, frontend node tests, production build, `npm audit --audit-level=moderate`, and Kubernetes manifest dry-run validation. +This includes TypeScript/Go linting, frontend Prettier formatting checks, Go tests, Python operator-runner tests, frontend node tests, production build, `npm audit --audit-level=moderate`, and Kubernetes manifest dry-run validation. ## Runtime Metrics diff --git a/internal/store/mongo_indexes.go b/internal/store/mongo_indexes.go new file mode 100644 index 00000000..f1281224 --- /dev/null +++ b/internal/store/mongo_indexes.go @@ -0,0 +1,97 @@ +package store + +import ( + "context" + + "go.mongodb.org/mongo-driver/bson" + "go.mongodb.org/mongo-driver/mongo" + "go.mongodb.org/mongo-driver/mongo/options" +) + +func uniqueIndex(name string, keys bson.D) mongo.IndexModel { + return mongo.IndexModel{ + Keys: keys, + Options: options.Index().SetName(name).SetUnique(true), + } +} + +func index(name string, keys bson.D) mongo.IndexModel { + return mongo.IndexModel{ + Keys: keys, + Options: options.Index().SetName(name), + } +} + +func ensureCollectionIndexes(ctx context.Context, collection *mongo.Collection, models []mongo.IndexModel) error { + if len(models) == 0 { + return nil + } + _, err := collection.Indexes().CreateMany(ctx, models) + return err +} + +func (store *MongoStore) EnsureIndexes(ctx context.Context) error { + indexesByCollection := map[*mongo.Collection][]mongo.IndexModel{ + store.projects: { + uniqueIndex("id_unique", bson.D{{Key: "id", Value: 1}}), + index("status_createdAt", bson.D{{Key: "status", Value: 1}, {Key: "createdAt", Value: -1}}), + }, + store.operators: { + uniqueIndex("id_unique", bson.D{{Key: "id", Value: 1}}), + index("category_name", bson.D{{Key: "category", Value: 1}, {Key: "name", Value: 1}}), + }, + store.builtinOperatorDeletions: { + uniqueIndex("id_unique", bson.D{{Key: "id", Value: 1}}), + }, + store.workflows: { + uniqueIndex("id_unique", bson.D{{Key: "id", Value: 1}}), + index("projectId_createdAt", bson.D{{Key: "projectId", Value: 1}, {Key: "createdAt", Value: -1}}), + index("type_status_lastRunAt", bson.D{{Key: "type", Value: 1}, {Key: "status", Value: 1}, {Key: "lastRunAt", Value: -1}}), + }, + store.templates: { + uniqueIndex("id_unique", bson.D{{Key: "id", Value: 1}}), + index("createdAt", bson.D{{Key: "createdAt", Value: -1}}), + }, + store.runs: { + uniqueIndex("id_unique", bson.D{{Key: "id", Value: 1}}), + index("status_availableAt_createdAt", bson.D{{Key: "status", Value: 1}, {Key: "availableAt", Value: 1}, {Key: "createdAt", Value: -1}}), + index("workflowId_createdAt", bson.D{{Key: "workflowId", Value: 1}, {Key: "createdAt", Value: -1}}), + index("projectId_createdAt", bson.D{{Key: "projectId", Value: 1}, {Key: "createdAt", Value: -1}}), + }, + store.sourceStates: { + uniqueIndex("workflow_node_fingerprint_unique", bson.D{{Key: "workflowId", Value: 1}, {Key: "nodeId", Value: 1}, {Key: "sourceFingerprint", Value: 1}}), + index("workflowId_nodeId", bson.D{{Key: "workflowId", Value: 1}, {Key: "nodeId", Value: 1}}), + }, + store.auditTasks: { + uniqueIndex("id_unique", bson.D{{Key: "id", Value: 1}}), + index("status_createdAt", bson.D{{Key: "status", Value: 1}, {Key: "createdAt", Value: -1}}), + index("runId_nodeId", bson.D{{Key: "runId", Value: 1}, {Key: "nodeId", Value: 1}}), + index("workflowId_createdAt", bson.D{{Key: "workflowId", Value: 1}, {Key: "createdAt", Value: -1}}), + }, + store.samplingTasks: { + uniqueIndex("id_unique", bson.D{{Key: "id", Value: 1}}), + index("status_createdAt", bson.D{{Key: "status", Value: 1}, {Key: "createdAt", Value: -1}}), + index("workflowId_createdAt", bson.D{{Key: "workflowId", Value: 1}, {Key: "createdAt", Value: -1}}), + }, + store.users: { + uniqueIndex("id_unique", bson.D{{Key: "id", Value: 1}}), + }, + store.storageConnections: { + uniqueIndex("id_unique", bson.D{{Key: "id", Value: 1}}), + index("name", bson.D{{Key: "name", Value: 1}}), + }, + store.mongoConnections: { + uniqueIndex("id_unique", bson.D{{Key: "id", Value: 1}}), + index("name", bson.D{{Key: "name", Value: 1}}), + }, + store.settings: { + uniqueIndex("id_unique", bson.D{{Key: "id", Value: 1}}), + }, + } + for collection, models := range indexesByCollection { + if err := ensureCollectionIndexes(ctx, collection, models); err != nil { + return err + } + } + return nil +} diff --git a/package-lock.json b/package-lock.json index b13c21a7..e45cfdd8 100644 --- a/package-lock.json +++ b/package-lock.json @@ -28,6 +28,7 @@ "autoprefixer": "^10.4.21", "concurrently": "^10.0.3", "playwright": "^1.59.1", + "prettier": "^3.8.4", "tailwindcss": "^4.1.14", "typescript": "~5.8.2", "vite": "^8.0.16" @@ -2531,6 +2532,22 @@ "dev": true, "license": "MIT" }, + "node_modules/prettier": { + "version": "3.8.4", + "resolved": "https://registry.npmjs.org/prettier/-/prettier-3.8.4.tgz", + "integrity": "sha512-N2MylSdi48+5N/6S5j+maeHbUSIzzZ5uOcX5Hm4QpV8Dkb1HFjfAKTKX6yNPJQD9AhcT3ifHNB66tWTTJDi11Q==", + "dev": true, + "license": "MIT", + "bin": { + "prettier": "bin/prettier.cjs" + }, + "engines": { + "node": ">=14" + }, + "funding": { + "url": "https://github.com/prettier/prettier?sponsor=1" + } + }, "node_modules/react": { "version": "19.2.4", "resolved": "https://registry.npmjs.org/react/-/react-19.2.4.tgz", diff --git a/package.json b/package.json index 6b2830fe..630ff931 100644 --- a/package.json +++ b/package.json @@ -21,11 +21,13 @@ "lint": "npm run lint:web && npm run lint:go", "lint:web": "tsc --noEmit", "lint:go": "bash -lc 'test -z \"$(gofmt -l cmd internal)\"'", + "format": "prettier --write \"src/**/*.{ts,tsx,css}\" \"tests/frontend/**/*.mjs\"", + "format:check": "prettier --check \"src/**/*.{ts,tsx,css}\" \"tests/frontend/**/*.mjs\"", "test": "go test ./...", "test:python": "python3 -m pytest backend/operator-runner tests/backend", "test:frontend": "node --test tests/frontend/*.test.mjs", "audit:moderate": "npm audit --audit-level=moderate", - "verify": "npm run lint && npm test && npm run test:python && npm run test:frontend && npm run build && npm run audit:moderate && npm run k8s:validate", + "verify": "npm run lint && npm run format:check && npm test && npm run test:python && npm run test:frontend && npm run build && npm run audit:moderate && npm run k8s:validate", "docker:build:api": "docker build -f Dockerfile.api -t droboticflow-api:local .", "docker:build:worker": "docker build -f Dockerfile.worker -t droboticflow-worker:local .", "docker:build:operator-runner": "docker build -f Dockerfile.operator-runner -t droboticflow-operator-runner:local .", @@ -56,6 +58,7 @@ "autoprefixer": "^10.4.21", "concurrently": "^10.0.3", "playwright": "^1.59.1", + "prettier": "^3.8.4", "tailwindcss": "^4.1.14", "typescript": "~5.8.2", "vite": "^8.0.16" diff --git a/src/App.tsx b/src/App.tsx index 530cbc7b..9b9c89f0 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -22,17 +22,11 @@ const Audit = lazy(() => import("./pages/Audit")); const DataAssets = lazy(() => import("./pages/DataAssets")); const DatabaseBrowser = lazy(() => import("./pages/DatabaseBrowser")); const ObjectStorageBrowser = lazy(() => import("./pages/ObjectStorageBrowser")); -const LegacyDataAssetsRedirect = lazy( - () => import("./pages/LegacyDataAssetsRedirect"), -); +const LegacyDataAssetsRedirect = lazy(() => import("./pages/LegacyDataAssetsRedirect")); const Sampling = lazy(() => import("./pages/Sampling")); function RouteFallback() { - return ( -
- 正在加载页面... -
- ); + return
正在加载页面...
; } export default function App() { @@ -50,18 +44,9 @@ export default function App() { } /> } /> } /> - } - /> - } - /> - } - /> + } /> + } /> + } /> } /> } /> } /> diff --git a/src/components/AIGenerateModal.tsx b/src/components/AIGenerateModal.tsx index 6ececfe9..129be05e 100644 --- a/src/components/AIGenerateModal.tsx +++ b/src/components/AIGenerateModal.tsx @@ -23,11 +23,14 @@ export default function AIGenerateModal({ isOpen, onClose, onGenerate }: AIGener if (!isOpen) { return; } - operatorsApi.list().then(setAvailableOperators).catch((err) => { - console.error("Failed to load operators for AI generation", err); - setAvailableOperators([]); - setError("无法加载真实算子列表,暂时不能生成工作流。"); - }); + operatorsApi + .list() + .then(setAvailableOperators) + .catch((err) => { + console.error("Failed to load operators for AI generation", err); + setAvailableOperators([]); + setError("无法加载真实算子列表,暂时不能生成工作流。"); + }); }, [isOpen]); const handleGenerate = async () => { @@ -65,11 +68,11 @@ export default function AIGenerateModal({ isOpen, onClose, onGenerate }: AIGener
-