Repository navigation
perf(search): adopt Get Filtered Team Tasks instead of crawling every list - #48
Conversation
Note: four files removed from this branchHeads up if you are working on this branch — I pushed a commit removing four files that did not belong to it.
They now live on their own in #50, against a clean Nothing on this branch depended on them: no code here references The search/export work itself is untouched — I have not reviewed it yet, and will do that separately. |
Updated against
|
39a30bc to
845af6c
Compare
… 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>
845af6c to
9d9730d
Compare
Summary
Fixes #25.
task searchandexport taskswalked workspace → spaces → folders → lists and calledGetTasksper list. Three problems, all of which this replaces with one server-side query per workspace againstGET /team/{team_id}/task:export.godiscardedGetFolders/GetListserrors (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
DefaultMaxTaskPagesand returnsTruncatedwhen 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
paginateso 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
searchreturns — on this workspace,search cuwent 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:--include-closedand--subtasksflags on both commands.--spacegiven 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.FindTasksByCustomFieldandcu 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.A field id works anywhere; a field name is resolved against
--listor the default list, since fields are only enumerable per list. No match exits 0 with an empty result rather than erroring.Tests
TestPaginatecovers 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.TestTeamTaskQueryToSDKcovers filter pass-through and omission of empty filters.Checklist
./scripts/ci.shpasses locally — excepterrcheck, which reports the same pre-existing findings onmain, none in files this PR touchescu docs markdown --dir docs/site/commands) andcu field findadded to the mkdocs navReview fixes
--space(search, export) now goes to the API asspace_ids[], and export's--status/--assigneego asstatuses[]/assignees[]. A username passed to--assigneeis 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".--prioritystays client-side because the endpoint can't filter on it. An unknown--spaceis now an error instead of an empty result.TeamTaskQueryalso acceptsProjectIDs/ListIDs.internal/api/teamtasks.goand no longer goes throughclickup.GetTasksOptions, whose custom_fields encoder builds JSON by joining strings, so a value containing"or\produced a broken filter.custom_fieldsis now built withjson.Marshal.cu field findresolution. A field id (UUID) is used as given, even when a default list is set. A field name is resolved against--listor 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 got400 VALID_012. The command now setsSilenceUsage, and it prints[]rather thannullwhen nothing matches.task searchnow exits whenGetSpacesfails, the same as export.FindTasksByCustomFieldreturns the page result, sofield findwarns 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.page=N,space_ids[],statuses[], escapedcustom_fields) and the total forSearchTeamTasksandListTasksAllPages, plus truncation at the cap.TestTeamTaskQueryToSDKhas been replaced byTestTeamTaskQueryValues.field findresolution has its own tests.main. Thechore(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 intomain, so this PR no longer touches config.main's binary:cu task search cureturned 2 tasks with both (same IDs),cu export tasks --format jsonreturned 26 with both, and--status "in development"returned 11 with both.🤖 Generated with Claude Code