diff --git a/internal/api/annotation_operations.go b/internal/api/annotation_operations.go index 11ddd724..2c7ee14c 100644 --- a/internal/api/annotation_operations.go +++ b/internal/api/annotation_operations.go @@ -622,6 +622,18 @@ func (server *server) handleAnnotationTasksList(writer http.ResponseWriter, requ artifactID := strings.TrimSpace(request.URL.Query().Get("artifactId")) rawLimit := strings.TrimSpace(request.URL.Query().Get("limit")) rawCursor := strings.TrimSpace(request.URL.Query().Get("cursor")) + // ids=a,b,c serves pool-item joins: the client's pool page already decided + // which human items it can see, so the task fetch targets exactly their + // legacyTaskIds instead of a newest-first window that may not contain + // them (the join regression behind 任务关联数据缺失). + requestedIDs := []string{} + if rawIDs := strings.TrimSpace(request.URL.Query().Get("ids")); rawIDs != "" { + for _, id := range strings.Split(rawIDs, ",") { + if id = strings.TrimSpace(id); id != "" { + requestedIDs = append(requestedIDs, id) + } + } + } var cursorCreatedAt, cursorID string if rawCursor != "" { payload, cursorErr := base64.RawURLEncoding.DecodeString(rawCursor) @@ -647,8 +659,11 @@ func (server *server) handleAnnotationTasksList(writer http.ResponseWriter, requ if parsed, issue := parseDatabaseBrowserPageQuery(rawLimit, "limit", 0, 1, 10000); issue == nil && rawLimit != "" { limit = int64(parsed) } + if len(requestedIDs) > 0 { + limit = 0 + } items, err := server.store.ListAnnotationTasksFiltered(request.Context(), server.requestOrganizationID(request), store.AnnotationTaskFilter{ - ProjectID: projectID, Status: string(status), SupplierID: supplierID, WorkflowID: workflowID, RunID: runID, NodeID: nodeID, ArtifactID: artifactID, + ProjectID: projectID, Status: string(status), SupplierID: supplierID, WorkflowID: workflowID, RunID: runID, NodeID: nodeID, ArtifactID: artifactID, IDs: requestedIDs, Limit: limit, CursorCreatedAt: cursorCreatedAt, CursorID: cursorID, }) listTasksMs = time.Since(segment).Milliseconds() @@ -844,7 +859,7 @@ func (server *server) handleAnnotationTasksList(writer http.ResponseWriter, requ response := map[string]any{"items": filtered} // Pagination metadata appears only for explicitly limited requests so the // legacy unbounded body stays byte-compatible. - if limit > 0 && len(items) == int(limit) { + if limit > 0 && len(requestedIDs) == 0 && len(items) == int(limit) { last := items[len(items)-1] payload, encodeErr := json.Marshal(map[string]string{"createdAt": last.CreatedAt, "id": last.ID}) if encodeErr == nil { @@ -880,7 +895,7 @@ func (server *server) handleAnnotationTaskGet(writer http.ResponseWriter, reques return } if linkedHumanItem != nil && !annotationManager(principal) && !server.canAccessCurrentHumanStage(request.Context(), request, *linkedHumanItem) && !isAuthor && !server.canReadReviewedHumanItem(request.Context(), request, *linkedHumanItem) { - renderJSON(writer, http.StatusForbidden, map[string]string{"error": "current human stage role is required", "code": "current_human_stage_role_required"}) + renderJSON(writer, http.StatusForbidden, map[string]string{"error": "current human stage role is required"}) return } item.ContinuousActions = server.continuousActionsForItem(request.Context(), linkedHumanItem) @@ -1188,7 +1203,7 @@ func (server *server) handleAnnotationTaskFrameTimelineGet(writer http.ResponseW } principal, _ := currentPrincipal(request) if linkedHumanItem != nil && !annotationManager(principal) && !server.canAccessCurrentHumanStage(request.Context(), request, *linkedHumanItem) && !server.canReadReviewedHumanItem(request.Context(), request, *linkedHumanItem) { - renderJSON(writer, http.StatusForbidden, map[string]string{"error": "current human stage role is required", "code": "current_human_stage_role_required"}) + renderJSON(writer, http.StatusForbidden, map[string]string{"error": "current human stage role is required"}) return } camera := strings.ToLower(strings.TrimSpace(request.URL.Query().Get("camera"))) diff --git a/internal/api/annotation_random_claim.go b/internal/api/annotation_random_claim.go index e23ddd14..cf8364c3 100644 --- a/internal/api/annotation_random_claim.go +++ b/internal/api/annotation_random_claim.go @@ -129,18 +129,28 @@ func (s *server) handleAnnotationClaimCount(w http.ResponseWriter, r *http.Reque renderError(w, 500, err) return } + // One batched read for every candidate's batch instead of a per-candidate + // point lookup (12k+ lookups on the legacy-batch organization). + batchIDs := make([]string, 0, len(candidates)) + seenBatchIDs := make(map[string]struct{}, len(candidates)) + for _, c := range candidates { + if _, seen := seenBatchIDs[c.BatchID]; !seen { + seenBatchIDs[c.BatchID] = struct{}{} + batchIDs = append(batchIDs, c.BatchID) + } + } + batchRecords, err := s.store.ListHumanBatchAccessRecords(r.Context(), p.User.OrganizationID, batchIDs) + if err != nil { + renderError(w, 500, err) + return + } batches := map[string]*domain.HumanBatchRecord{} + for index := range batchRecords { + batches[batchRecords[index].ID] = &batchRecords[index] + } count := 0 for _, c := range candidates { - b, loaded := batches[c.BatchID] - if !loaded { - b, err = s.store.GetHumanBatch(r.Context(), c.BatchID) - if err != nil { - renderError(w, 500, err) - return - } - batches[c.BatchID] = b - } + b := batches[c.BatchID] legacy := domain.AnnotationTaskRecord{ID: c.LegacyTaskID, ProjectID: c.ProjectID, SupplierID: c.SupplierID, ProcessingScope: c.ProcessingScope, ProcessingProfile: c.ProcessingProfile} legacy.SupplierPool = b != nil && b.ProcessingProfile == domain.ProcessingProfileRawHuman && domain.IsFanyuV58ThreeRoleHumanLoop(b.Stages) if !membershipHasRole(members, legacy, domain.AnnotationRoleAnnotator) || (c.SupplierID != "" && !suppliers[c.SupplierID]) { diff --git a/internal/api/human_loop.go b/internal/api/human_loop.go index b3c0d608..0b98c1ab 100644 --- a/internal/api/human_loop.go +++ b/internal/api/human_loop.go @@ -12,6 +12,7 @@ import ( "log" "net/http" "reflect" + "slices" "sort" "strconv" "strings" @@ -176,6 +177,19 @@ func parseHumanItemQuery(request *http.Request) (domain.HumanItemQuery, *validat WorkflowID: values.Get("workflowId"), RunID: values.Get("runId"), CurrentStageID: values.Get("stageId"), Status: domain.HumanItemStatus(values.Get("status")), } + // stageIds=a,b,c pushes the role workspace's stage set into the store + // query. The single-value stageId stays supported; combining both merges + // the sets. + if raw := strings.TrimSpace(values.Get("stageIds")); raw != "" { + for _, stage := range strings.Split(raw, ",") { + if stage = strings.TrimSpace(stage); stage != "" { + query.StageIDs = append(query.StageIDs, stage) + } + } + } + if query.CurrentStageID != "" && !slices.Contains(query.StageIDs, query.CurrentStageID) { + query.StageIDs = append(query.StageIDs, query.CurrentStageID) + } // Reject malformed cursors like the runs endpoint instead of silently // falling back to the first page. cursor, err := decodeHumanItemCursor(values.Get("cursor")) diff --git a/internal/domain/human_loop.go b/internal/domain/human_loop.go index f88d4209..b8572ba4 100644 --- a/internal/domain/human_loop.go +++ b/internal/domain/human_loop.go @@ -333,6 +333,11 @@ type HumanItemQuery struct { // endpoint so Mongo skips rows the handler would drop anyway. UnassignedOnly bool Statuses []HumanItemStatus + // StageIDs pushes a multi-stage filter into the store query. Role pools + // (available/all) previously filtered stages in-memory only, which left + // the database sorting the whole unassigned backlog (17k docs, ~7s per + // fetch round) before the handler dropped almost every row. + StageIDs []string } type HumanRejectQuery struct { diff --git a/internal/store/annotation_operations.go b/internal/store/annotation_operations.go index 57621cd5..0a781b4c 100644 --- a/internal/store/annotation_operations.go +++ b/internal/store/annotation_operations.go @@ -180,6 +180,21 @@ func (store *MemoryStore) ListAnnotationTasksFiltered(_ context.Context, organiz store.mu.Lock() defer store.mu.Unlock() matches := func(value string, expected string) bool { return expected == "" || value == expected } + // An explicit ID set serves pool-item joins (see MongoStore). + if len(filter.IDs) > 0 { + wanted := make(map[string]bool, len(filter.IDs)) + for _, id := range filter.IDs { + wanted[id] = true + } + items := make([]domain.AnnotationTaskRecord, 0, len(wanted)) + for _, item := range store.annotationTasks { + if wanted[item.ID] && annotationOrganizationMatches(item.OrganizationID, organizationID) { + items = append(items, item) + } + } + sortAnnotationRecords(items, func(item domain.AnnotationTaskRecord) string { return item.CreatedAt }) + return items, nil + } items := make([]domain.AnnotationTaskRecord, 0) for _, item := range store.annotationTasks { if annotationOrganizationMatches(item.OrganizationID, organizationID) && @@ -656,6 +671,10 @@ type AnnotationTaskFilter struct { RunID string NodeID string ArtifactID string + // IDs requests a specific task-ID set (pool-item joins). When set, the + // other equality filters and the cursor are ignored and the id_unique + // index serves the lookup directly. + IDs []string // Limit caps the page size (0 = unbounded, the legacy behavior). Limit int64 // Cursor resumes strictly after (CreatedAt, ID) in the descending order. @@ -691,7 +710,18 @@ func (store *MongoStore) ListAnnotationTasksFiltered(ctx context.Context, organi extra["artifactId"] = filter.ArtifactID } query := mongoAnnotationFilter(organizationID, extra) - if filter.CursorID != "" { + // An explicit ID set serves pool-item joins: the caller's pool page + // decides which tasks it needs, so fetch exactly those (id_unique index) + // instead of re-deriving them through the cursor window. + if len(filter.IDs) > 0 { + ids := make(bson.A, 0, len(filter.IDs)) + for _, id := range filter.IDs { + ids = append(ids, id) + } + query["id"] = bson.M{"$in": ids} + delete(query, "$or") + } + if len(filter.IDs) == 0 && filter.CursorID != "" { cursorTail := bson.A{bson.M{"createdAt": bson.M{"$lt": filter.CursorCreatedAt}}, bson.M{"createdAt": filter.CursorCreatedAt, "id": bson.M{"$lt": filter.CursorID}}} query["$or"] = cursorTail } diff --git a/internal/store/human_loop.go b/internal/store/human_loop.go index 558d3b56..00d8b382 100644 --- a/internal/store/human_loop.go +++ b/internal/store/human_loop.go @@ -594,6 +594,13 @@ func humanItemMongoFilter(organizationID string, query domain.HumanItemQuery) bs if query.CurrentStageID != "" { filter["currentStageId"] = query.CurrentStageID } + if len(query.StageIDs) > 0 { + stages := make(bson.A, 0, len(query.StageIDs)) + for _, stage := range query.StageIDs { + stages = append(stages, stage) + } + filter["currentStageId"] = bson.M{"$in": stages} + } if query.Status != "" { filter["status"] = query.Status } @@ -889,7 +896,7 @@ func (store *MongoStore) ListHumanBatchAccessRecords(ctx context.Context, organi if len(ids) == 0 { return []domain.HumanBatchRecord{}, nil } - cursor, err := store.humanBatches.Find(ctx, bson.M{"organizationId": normalizedOrganizationID(organizationID), "id": bson.M{"$in": ids}}, options.Find().SetProjection(bson.M{"_id": 0, "id": 1, "organizationId": 1, "projectId": 1, "stages": 1, "processingProfile": 1, "sourceBatchId": 1, "processingScope": 1, "requirePrePackageAcceptance": 1})) + cursor, err := store.humanBatches.Find(ctx, bson.M{"organizationId": normalizedOrganizationID(organizationID), "id": bson.M{"$in": ids}}, options.Find().SetProjection(bson.M{"_id": 0, "id": 1, "organizationId": 1, "projectId": 1, "stages": 1, "processingProfile": 1, "status": 1, "sourceBatchId": 1, "processingScope": 1, "requirePrePackageAcceptance": 1})) if err != nil { return nil, err } @@ -908,7 +915,7 @@ func (store *MemoryStore) ListHumanBatchAccessRecords(ctx context.Context, organ return nil, err } if b != nil && b.OrganizationID == normalizedOrganizationID(organizationID) { - items = append(items, domain.HumanBatchRecord{ID: b.ID, OrganizationID: b.OrganizationID, ProjectID: b.ProjectID, Stages: b.Stages, ProcessingProfile: b.ProcessingProfile, SourceBatchID: b.SourceBatchID, ProcessingScope: b.ProcessingScope, RequirePrePackageAcceptance: b.RequirePrePackageAcceptance}) + items = append(items, domain.HumanBatchRecord{ID: b.ID, OrganizationID: b.OrganizationID, ProjectID: b.ProjectID, Stages: b.Stages, ProcessingProfile: b.ProcessingProfile, Status: b.Status, SourceBatchID: b.SourceBatchID, ProcessingScope: b.ProcessingScope, RequirePrePackageAcceptance: b.RequirePrePackageAcceptance}) } } return items, nil diff --git a/src/components/MoviVideo.tsx b/src/components/MoviVideo.tsx index 11bf6e79..faf7f770 100644 --- a/src/components/MoviVideo.tsx +++ b/src/components/MoviVideo.tsx @@ -69,6 +69,19 @@ const EVENT_BRIDGE: Array<[keyof MoviVideoEventMap, string]> = [ const BOOLEAN_ATTRIBUTES = new Set(["nohotkeys", "controls", "muted", "playsinline"]); +// Retry delays (ms) used to find the shadow