11import chalk from 'chalk'
22import { Command } from 'commander'
3- import { getApi , getCurrentUserId , type Task } from '../lib/api/core.js'
3+ import { getApi , type Task } from '../lib/api/core.js'
44import { CollaboratorCache , formatAssignee } from '../lib/collaborators.js'
55import { formatDateHeader , getLocalDate , isDueBefore } from '../lib/dates.js'
66import {
@@ -10,7 +10,7 @@ import {
1010 formatTaskRow ,
1111} from '../lib/output.js'
1212import { LIMITS , paginate } from '../lib/pagination.js'
13- import { filterByWorkspaceOrPersonal } from '../lib/task-list.js'
13+ import { fetchProjects , filterByWorkspaceOrPersonal } from '../lib/task-list.js'
1414
1515interface UpcomingOptions {
1616 limit ?: string
@@ -57,33 +57,33 @@ export function registerUpcomingCommand(program: Command): void {
5757
5858 const today = getLocalDate ( 0 )
5959
60- const { results : tasks , nextCursor } = await paginate (
61- ( cursor , limit ) =>
62- api . getTasksByFilter ( {
63- query : `due before: ${ days } days` ,
64- cursor : cursor ?? undefined ,
65- limit ,
66- } ) ,
67- { limit : targetLimit , startCursor : options . cursor } ,
68- )
69-
70- let filteredTasks = tasks
71- if ( ! options . anyAssignee ) {
72- const currentUserId = await getCurrentUserId ( )
73- filteredTasks = tasks . filter (
74- ( t ) => ! t . responsibleUid || t . responsibleUid === currentUserId ,
75- )
76- }
60+ const baseQuery = `due before: ${ days } days`
61+ const query = options . anyAssignee
62+ ? baseQuery
63+ : `( ${ baseQuery } ) & (assigned to: me | !assigned)`
64+
65+ const [ { results : tasks , nextCursor } , projects ] = await Promise . all ( [
66+ paginate (
67+ ( cursor , limit ) =>
68+ api . getTasksByFilter ( {
69+ query ,
70+ cursor : cursor ?? undefined ,
71+ limit ,
72+ } ) ,
73+ { limit : targetLimit , startCursor : options . cursor } ,
74+ ) ,
75+ fetchProjects ( api ) ,
76+ ] )
7777
78- const filterResult = await filterByWorkspaceOrPersonal (
78+ const filterResult = await filterByWorkspaceOrPersonal ( {
7979 api,
80- filteredTasks ,
81- options . workspace ,
82- options . personal ,
83- )
84- filteredTasks = filterResult . tasks
80+ tasks ,
81+ workspace : options . workspace ,
82+ personal : options . personal ,
83+ prefetchedProjects : projects ,
84+ } )
8585
86- const relevantTasks = filteredTasks
86+ const relevantTasks = filterResult . tasks
8787
8888 if ( options . json ) {
8989 console . log (
@@ -109,9 +109,8 @@ export function registerUpcomingCommand(program: Command): void {
109109 return
110110 }
111111
112- const { projects } = filterResult
113112 const collaboratorCache = new CollaboratorCache ( )
114- await collaboratorCache . preload ( api , relevantTasks , projects )
113+ await collaboratorCache . preload ( api , relevantTasks , filterResult . projects )
115114
116115 if ( relevantTasks . length === 0 ) {
117116 console . log ( `No tasks due in the next ${ days } day${ days === 1 ? '' : 's' } .` )
0 commit comments