Skip to content

perf(search): adopt Get Filtered Team Tasks instead of crawling every list - #48

Merged
timimsms merged 2 commits into
mainfrom
feat/filtered-team-tasks
Nov 15, 2026
Merged

timimsms merged 2 commits into
mainfrom
feat/filtered-team-tasks

Conversation

@timimsms

@timimsms timimsms commented Aug 29, 2026 •

Copy link
Copy Markdown
Owner

Summary

Fixes #25. task search and export tasks walked workspace → spaces → folders → lists and called GetTasks per list. Three problems, all of which this replaces with one server-side query per workspace against GET /team/{team_id}/task:

  1. One request per list under a 100 req/min limit.
  2. Silent truncation — only page 0 was fetched per list, so any list past 100 tasks was quietly cut off.
  3. Silently partial exports — export.go discarded GetFolders/GetLists errors (folders, _ := …), so whole subtrees could vanish and the export still reported success.

Measured on a small real workspace, task search: 3.74s → 1.14s. The gap widens with list count, since the old cost was linear in lists and the new one is linear in pages of results.

Truncation is now reported, not hidden

Pagination is bounded by DefaultMaxTaskPages and returns Truncated when it stops early, so a capped result is never presented as complete — that being the actual bug in this issue. Both commands print a warning when it happens.

The paging loop is extracted as paginate so termination and truncation are testable without a network round trip.

Behaviour is deliberately unchanged by default

The team endpoint can return closed tasks and subtasks, which the per-list crawl never did. Turning that on by default would have quietly changed what search returns — on this workspace, search cu went from 2 results to 4, the extra two being subtasks. That is a better answer, but it is not what this issue asked for, so:

  • defaults mirror the old crawl (open tasks, no subtasks), and I verified default results match v0.2.1 exactly on a real workspace;
  • the fuller set is reachable via new --include-closed and --subtasks flags on both commands.

--space given as a name still works: tasks carry only a space id, so the name is resolved to an id first rather than dropping the capability.

New: reverse lookup

Client.FindTasksByCustomField and cu field find — from a value stored in a custom field back to the task holding it. The crawl could not do this at any acceptable cost; the endpoint filters custom fields server-side.

$ cu field find Repo https://github.com/timimsms/cu
id          name        status      list          url
86dxbeqyt   cu          in review   R&D Projects  https://app.clickup.com/t/86dxbeqyt

A field id works anywhere; a field name is resolved against --list or the default list, since fields are only enumerable per list. No match exits 0 with an empty result rather than erroring.

Tests

TestPaginate covers stopping on a short page, a single short page, an empty first page, the exactly-full-last-page case (which costs one extra request to discover), hitting the cap and reporting truncation, and errors aborting rather than returning a partial set. TestTeamTaskQueryToSDK covers filter pass-through and omission of empty filters.

Checklist

  • ./scripts/ci.sh passes locally — except errcheck, which reports the same pre-existing findings on main, none in files this PR touches
  • Commit messages use conventional prefixes
  • CLI docs regenerated (cu docs markdown --dir docs/site/commands) and cu field find added to the mkdocs nav
  • Docs updated if user-facing behavior changed — README feature list and examples

Review fixes

  • Server-side filters. --space (search, export) now goes to the API as space_ids[], and export's --status / --assignee go as statuses[] / assignees[]. A username passed to --assignee is resolved to a user id first. Before this, all three were applied after paging, so with the 50-page cap a narrow filter in a large workspace could come back empty and only "truncated". --priority stays client-side because the endpoint can't filter on it. An unknown --space is now an error instead of an empty result. TeamTaskQuery also accepts ProjectIDs / ListIDs.
  • custom_fields escaping. The query is now encoded in internal/api/teamtasks.go and no longer goes through clickup.GetTasksOptions, whose custom_fields encoder builds JSON by joining strings, so a value containing " or \ produced a broken filter. custom_fields is now built with json.Marshal.
  • cu field find resolution. A field id (UUID) is used as given, even when a default list is set. A field name is resolved against --list or the default list. If neither exists, the command now tells you to pass --list, where before it sent the name to the API as a field_id and got 400 VALID_012. The command now sets SilenceUsage, and it prints [] rather than null when nothing matches.
  • Nits. task search now exits when GetSpaces fails, the same as export. FindTasksByCustomField returns the page result, so field find warns on truncation. The truncation warnings now name the flags that narrow a search; they used to tell you to raise a page cap that no flag controls.
  • Tests. httptest coverage serves pages of 100, 100 and 3 tasks and checks the raw query strings (page=N, space_ids[], statuses[], escaped custom_fields) and the total for SearchTeamTasks and ListTasksAllPages, plus truncation at the cap. TestTeamTaskQueryToSDK has been replaced by TestTeamTaskQueryValues. field find resolution has its own tests.
  • Rebase. Rebased onto current main. The chore(config) commit that removed the credential-surface files was dropped because fix(config): redact credentials in config get and refuse them in .cu.yml #50 has merged those files into main, so this PR no longer touches config.
  • Live read-only check against main's binary: cu task search cu returned 2 tasks with both (same IDs), cu export tasks --format json returned 26 with both, and --status "in development" returned 11 with both.

🤖 Generated with Claude Code

@timimsms

Copy link
Copy Markdown
Owner Author

Note: four files removed from this branch

Heads up if you are working on this branch — I pushed a commit removing four files that did not belong to it.

internal/config/config.go, internal/config/config_test.go, internal/cmd/config.go and internal/cmd/config_test.go were swept into ac05574 by a broad git add, while an unrelated change was uncommitted in the same working tree. The result was that a change to what cu config get prints, plus a new write guard on .cu.yml, arrived on a PR whose message describes only the search/export performance work — so a reviewer reading that message had no reason to look for a security-surface change.

They now live on their own in #50, against a clean main.

Nothing on this branch depended on them: no code here references GlobalConfigPath, stripCredentials, RedactedValue or IsCredentialKey, and go build, go vet and the full suite pass without them. I verified the branch head was still ac05574 immediately before pushing, so nothing of yours was overwritten.

The search/export work itself is untouched — I have not reviewed it yet, and will do that separately.

@timimsms

Copy link
Copy Markdown
Owner Author

Updated against main — one conflict, resolved

Brought main in so this reviews against what would actually merge. #50 and #51 had landed since ac05574, and #51 touches export.go.

One conflict, in the export flag block — exactly where the two changes met:

<<<<<<< HEAD
	exportTasksCmd.Flags().Bool("include-closed", ...)
	exportTasksCmd.Flags().Bool("subtasks", ...)
	exportTasksCmd.Flags().StringP("output", "o", "", "Output file (default: stdout)")
=======
	exportTasksCmd.Flags().StringP("file", "F", "", "Write to a file instead of stdout")
>>>>>>> origin/main

Resolved keeping both sides: this branch's two new filters stay, and the destination file remains on --file/-F with -o left to the global format flag, per #51. The rest of export.go auto-merged so that the run body reads --file for the destination and resolveExportFormat for the format — I checked that rather than assuming it.

Docs needed regenerating. The auto-merged cu_export_tasks.md still advertised -o as the output file, which stopped being true in #51. The page now shows -F, --file locally and -o under Options inherited as the format flag, alongside --include-closed and --subtasks. Datestamp-only pages reverted, per the convention from #47.

Verified on the merged result, not just built: the combined flag surface is correct, and #51's behavior survives intact — -o tasks.csv still errors with the --file hint rather than writing a junk file, and --format csv -o json still refuses to guess. Full suite, go vet and gofmt clean. CI is 16/16.

The branch now differs from main only by this PR's own work — I confirmed the config files are byte-identical to main, so #50 arrived through the merge rather than resurrecting the copies that were split out earlier.

Why a merge and not a rebase

Another session owns this branch. Force-pushing rewritten history over it is the one operation that could destroy work in progress, so this is an ordinary merge commit — which the repo already does elsewhere (Merge branch 'main' into docs/public-launch-prep). Say the word if you want it linearised once that session is done and I'll rebase properly.

Still unreviewed by me — that's next.

@timimsms
timimsms force-pushed the feat/filtered-team-tasks branch from 39a30bc to 845af6c Compare November 15, 2026 18:29
timimsms and others added 2 commits November 15, 2026 11:29
… list

`task search` and `export tasks` walked workspace → spaces → folders → lists and
called GetTasks per list. That cost one request per list under a 100 req/min
limit, and since only page 0 was ever fetched, any list past 100 tasks was
silently cut off. export also discarded GetFolders/GetLists errors, so it could
omit whole subtrees and still report success.

Both now issue one server-side query per workspace against
GET /team/{id}/task, paged to exhaustion. Against a small real workspace this
takes search from 3.7s to 1.1s; the gap widens with list count.

Pagination is bounded by DefaultMaxTaskPages and reports Truncated when it stops
early, so a capped result is never presented as a complete one — the failure
mode this issue is about. The paging loop is extracted as `paginate` so
termination and truncation are testable without a network round trip.

Search and export defaults deliberately mirror the old crawl (open tasks, no
subtasks) to keep this a performance fix; the endpoint makes the fuller set
reachable via new --include-closed and --subtasks flags. Verified that default
results match v0.2.1 exactly on a real workspace.

Adds Client.FindTasksByCustomField and `cu field find`, the reverse lookup from
a value stored in a custom field back to the task holding it, which the crawl
could not do at any acceptable cost.

Fixes #25

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_014aqbmccWm1tqttmBUCR5rv
ClickUp: 86dxbeqyt
…solution

Get Filtered Team Tasks accepts space_ids[], project_ids[], list_ids[],
statuses[] and assignees[], but --space (search, export) and --status /
--assignee (export) were applied after paging. With the 50-page cap a
narrow filter in a large workspace could come back empty and merely
"truncated". They now go to the server; only export's --priority, which
the endpoint cannot filter, stays client-side.

The query is encoded by hand instead of through clickup.GetTasksOptions:
the SDK lacks the location filters, and its custom_fields encoder joins
JSON strings without escaping, so a value containing " or \ produced a
malformed filter. custom_fields is now built with json.Marshal.

Also: task search exits on a GetSpaces failure like export does, an
unknown --space is an error rather than an empty result, and the
truncation warning names flags that exist instead of a "page cap" no
flag controls.

Adds httptest coverage that serves 100/100/3-task pages and asserts the
raw query strings for SearchTeamTasks and ListTasksAllPages.

field find: a field name with no --list and no default list was sent raw as
field_id (400 VALID_012), and with a default list set a field id from
another list failed lookup, contradicting "a field id works anywhere".
A UUID is now used as given; a name is resolved via the list, and with
no list available the command says to pass --list.

field find also sets SilenceUsage so API errors do not print usage, and
warns when the match set hit the page cap.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@timimsms
timimsms force-pushed the feat/filtered-team-tasks branch from 845af6c to 9d9730d Compare November 15, 2026 18:30
@timimsms
timimsms merged commit 5b68a0e into main Nov 15, 2026
16 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

search/export: unbounded N+1 workspace crawl with silent truncation; adopt Get Filtered Team Tasks

1 participant