Shared task board where people and AI coding agents work as teammates. Source-available, self-hostable.
Go
refactor(server): stop querying assignee frequency (#11644)
Multica Evee77b8abf92ab
diff --git a/server/internal/handler/activity.go b/server/internal/handler/activity.goindex ad9436e943..85ef7c19f3 100644--- a/server/internal/handler/activity.go+++ b/server/internal/handler/activity.go@@ -423,73 +423,17 @@ type AssigneeFrequencyEntry struct {Frequency int64 `json:"frequency"`}-// GetAssigneeFrequency returns assignee usage frequency for the current user,-// combining data from assignee change activities and initial issue assignments.+// GetAssigneeFrequency always returns an empty list (MUL-9724).+//+// Current clients rank the assignee picker from a local FIFO history and no+// longer call this endpoint. Only clients from before that change still do;+// they parse an empty list fine and fall back to their default ordering. The+// route, auth and response shape stay so those clients keep working, but the+// handler no longer runs the per-user frequency queries, which were expensive+// on activity_log. Drop the route once no old client calls it.func (h *Handler) GetAssigneeFrequency(w http.ResponseWriter, r *http.Request) {- userID, ok := requireUserID(w, r)- if !ok {- return- }- workspaceID := h.resolveWorkspaceID(r)-- // Aggregate frequency from both data sources.- freq := map[string]int64{} // key: "type:id"-- // Source 1: assignee_changed activities by this user.- activityCounts, err := h.Queries.CountAssigneeChangesByActor(r.Context(), db.CountAssigneeChangesByActorParams{- WorkspaceID: parseUUID(workspaceID),- ActorID: parseUUID(userID),- })- if err != nil {- writeError(w, http.StatusInternalServerError, "failed to get assignee frequency")- return- }- for _, row := range activityCounts {- aType, _ := row.AssigneeType.(string)- aID, _ := row.AssigneeID.(string)- if aType != "" && aID != "" {- freq[aType+":"+aID] += row.Frequency- }- }-- // Source 2: issues created by this user with an assignee.- issueCounts, err := h.Queries.CountCreatedIssueAssignees(r.Context(), db.CountCreatedIssueAssigneesParams{- WorkspaceID: parseUUID(workspaceID),- CreatorID: parseUUID(userID),- })- if err != nil {- writeError(w, http.StatusInternalServerError, "failed to get assignee frequency")+ if _, ok := requireUserID(w, r); !ok {return}- for _, row := range issueCounts {- if !row.AssigneeType.Valid || !row.AssigneeID.Valid {- continue- }- key := row.AssigneeType.String + ":" + uuidToString(row.AssigneeID)- freq[key] += row.Frequency- }-- // Build sorted response.- result := make([]AssigneeFrequencyEntry, 0, len(freq))- for key, count := range freq {- // Split "type:id" — type is always "member" or "agent" (no colons).- var aType, aID string- for i := 0; i < len(key); i++ {- if key[i] == ':' {- aType = key[:i]- aID = key[i+1:]- break- }- }- result = append(result, AssigneeFrequencyEntry{- AssigneeType: aType,- AssigneeID: aID,- Frequency: count,- })- }- sort.Slice(result, func(i, j int) bool {- return result[i].Frequency > result[j].Frequency- })-- writeJSON(w, http.StatusOK, result)+ writeJSON(w, http.StatusOK, []AssigneeFrequencyEntry{})}diff --git a/server/internal/handler/assignee_frequency_test.go b/server/internal/handler/assignee_frequency_test.gonew file mode 100644index 0000000000..84c21923b6--- /dev/null+++ b/server/internal/handler/assignee_frequency_test.go@@ -0,0 +1,48 @@+package handler++import (+ "encoding/json"+ "net/http"+ "net/http/httptest"+ "testing"+)++// The endpoint stays for clients from before the local FIFO assignee ordering+// (MUL-9724): same route and query parameters, 200 with a JSON array, but no+// database work. The handler has no Queries or DB pool, so any query would+// panic.+func TestGetAssigneeFrequencyReturnsEmptyListWithoutDB(t *testing.T) {+ h := &Handler{}+ req := httptest.NewRequest(http.MethodGet, "/api/assignee-frequency?workspace_id=00000000-0000-0000-0000-000000000001", nil)+ req.Header.Set("X-User-ID", "00000000-0000-0000-0000-000000000002")+ req.Header.Set("X-Workspace-ID", "00000000-0000-0000-0000-000000000001")+ w := httptest.NewRecorder()++ h.GetAssigneeFrequency(w, req)++ if w.Code != http.StatusOK {+ t.Fatalf("expected 200, got %d: %s", w.Code, w.Body.String())+ }+ if got := w.Body.String(); got != "[]\n" {+ t.Fatalf("expected an empty JSON array, got %q", got)+ }+ var entries []AssigneeFrequencyEntry+ if err := json.Unmarshal(w.Body.Bytes(), &entries); err != nil {+ t.Fatalf("old clients decode the body as a list: %v", err)+ }+ if len(entries) != 0 {+ t.Fatalf("expected no entries, got %+v", entries)+ }+}++func TestGetAssigneeFrequencyRequiresUser(t *testing.T) {+ h := &Handler{}+ req := httptest.NewRequest(http.MethodGet, "/api/assignee-frequency", nil)+ w := httptest.NewRecorder()++ h.GetAssigneeFrequency(w, req)++ if w.Code != http.StatusUnauthorized {+ t.Fatalf("expected 401, got %d: %s", w.Code, w.Body.String())+ }+}diff --git a/server/pkg/db/generated/activity.sql.go b/server/pkg/db/generated/activity.sql.goindex a3acfaa9fd..88ad0f79cf 100644--- a/server/pkg/db/generated/activity.sql.go+++ b/server/pkg/db/generated/activity.sql.go@@ -11,53 +11,6 @@ import ("github.com/jackc/pgx/v5/pgtype")-const countAssigneeChangesByActor = `-- name: CountAssigneeChangesByActor :many-SELECT- details->>'to_type' as assignee_type,- details->>'to_id' as assignee_id,- COUNT(*)::bigint as frequency-FROM activity_log-WHERE workspace_id = $1- AND actor_id = $2- AND actor_type = 'member'- AND action = 'assignee_changed'- AND details->>'to_type' IS NOT NULL- AND details->>'to_id' IS NOT NULL-GROUP BY details->>'to_type', details->>'to_id'-`--type CountAssigneeChangesByActorParams struct {- WorkspaceID pgtype.UUID `json:"workspace_id"`- ActorID pgtype.UUID `json:"actor_id"`-}--type CountAssigneeChangesByActorRow struct {- AssigneeType interface{} `json:"assignee_type"`- AssigneeID interface{} `json:"assignee_id"`- Frequency int64 `json:"frequency"`-}--// Count how many times a user assigned each target via assignee_changed activities.-func (q *Queries) CountAssigneeChangesByActor(ctx context.Context, arg CountAssigneeChangesByActorParams) ([]CountAssigneeChangesByActorRow, error) {- rows, err := q.db.Query(ctx, countAssigneeChangesByActor, arg.WorkspaceID, arg.ActorID)- if err != nil {- return nil, err- }- defer rows.Close()- items := []CountAssigneeChangesByActorRow{}- for rows.Next() {- var i CountAssigneeChangesByActorRow- if err := rows.Scan(&i.AssigneeType, &i.AssigneeID, &i.Frequency); err != nil {- return nil, err- }- items = append(items, i)- }- if err := rows.Err(); err != nil {- return nil, err- }- return items, nil-}-const countSquadMemberHandoffsSince = `-- name: CountSquadMemberHandoffsSince :oneSELECT count(*) FROM activity_logWHERE issue_id = $1diff --git a/server/pkg/db/generated/issue.sql.go b/server/pkg/db/generated/issue.sql.goindex 3caeb90ce6..8ae9ee8c0e 100644--- a/server/pkg/db/generated/issue.sql.go+++ b/server/pkg/db/generated/issue.sql.go@@ -129,52 +129,6 @@ func (q *Queries) ClearIssueDuplicatesOf(ctx context.Context, arg ClearIssueDuplreturn items, nil}-const countCreatedIssueAssignees = `-- name: CountCreatedIssueAssignees :many-SELECT- assignee_type,- assignee_id,- COUNT(*)::bigint as frequency-FROM issue-WHERE workspace_id = $1- AND creator_id = $2- AND creator_type = 'member'- AND assignee_type IS NOT NULL- AND assignee_id IS NOT NULL-GROUP BY assignee_type, assignee_id-`--type CountCreatedIssueAssigneesParams struct {- WorkspaceID pgtype.UUID `json:"workspace_id"`- CreatorID pgtype.UUID `json:"creator_id"`-}--type CountCreatedIssueAssigneesRow struct {- AssigneeType pgtype.Text `json:"assignee_type"`- AssigneeID pgtype.UUID `json:"assignee_id"`- Frequency int64 `json:"frequency"`-}--// Count assignees on issues created by a specific user.-func (q *Queries) CountCreatedIssueAssignees(ctx context.Context, arg CountCreatedIssueAssigneesParams) ([]CountCreatedIssueAssigneesRow, error) {- rows, err := q.db.Query(ctx, countCreatedIssueAssignees, arg.WorkspaceID, arg.CreatorID)- if err != nil {- return nil, err- }- defer rows.Close()- items := []CountCreatedIssueAssigneesRow{}- for rows.Next() {- var i CountCreatedIssueAssigneesRow- if err := rows.Scan(&i.AssigneeType, &i.AssigneeID, &i.Frequency); err != nil {- return nil, err- }- items = append(items, i)- }- if err := rows.Err(); err != nil {- return nil, err- }- return items, nil-}-const countIssues = `-- name: CountIssues :oneSELECT count(*) FROM issue iWHERE i.workspace_id = $1diff --git a/server/pkg/db/queries/activity.sql b/server/pkg/db/queries/activity.sqlindex f70785d039..3251e9750f 100644--- a/server/pkg/db/queries/activity.sql+++ b/server/pkg/db/queries/activity.sql@@ -44,21 +44,6 @@ SELECT EXISTS (AND details->>'task_id' = @task_id::text) AS exists;--- name: CountAssigneeChangesByActor :many--- Count how many times a user assigned each target via assignee_changed activities.-SELECT- details->>'to_type' as assignee_type,- details->>'to_id' as assignee_id,- COUNT(*)::bigint as frequency-FROM activity_log-WHERE workspace_id = $1- AND actor_id = $2- AND actor_type = 'member'- AND action = 'assignee_changed'- AND details->>'to_type' IS NOT NULL- AND details->>'to_id' IS NOT NULL-GROUP BY details->>'to_type', details->>'to_id';--- name: GetLastIssueStatusChange :one-- Who last changed an issue's status, and to what: names the mover when an-- agent's status change is refused because the issue left its step (MUL-7420).diff --git a/server/pkg/db/queries/issue.sql b/server/pkg/db/queries/issue.sqlindex 8962fdf8bd..2e3bed6e90 100644--- a/server/pkg/db/queries/issue.sql+++ b/server/pkg/db/queries/issue.sql@@ -678,20 +678,6 @@ WHERE workspace_id = $1AND origin_id = $3LIMIT 1;--- name: CountCreatedIssueAssignees :many--- Count assignees on issues created by a specific user.-SELECT- assignee_type,- assignee_id,- COUNT(*)::bigint as frequency-FROM issue-WHERE workspace_id = $1- AND creator_id = $2- AND creator_type = 'member'- AND assignee_type IS NOT NULL- AND assignee_id IS NOT NULL-GROUP BY assignee_type, assignee_id;--- name: ChildIssueProgress :manySELECT parent_issue_id,COUNT(*)::bigint AS total,