* Drains a single team's projects connection by following * `pageInfo.endCursor` until `hasNextPage` is false. Bounded by * `MAX_PROJECTS_PAGES`; logs a warning if the cap is hit so a truncated list * is visible rather than silently dropped.
(team: Team)
| 31 | * is visible rather than silently dropped. |
| 32 | */ |
| 33 | async function fetchAllTeamProjects(team: Team): Promise<Project[]> { |
| 34 | const projects: Project[] = [] |
| 35 | let after: string | undefined |
| 36 | |
| 37 | for (let page = 0; page < MAX_PROJECTS_PAGES; page++) { |
| 38 | const result = await team.projects({ first: LINEAR_PAGE_SIZE, after }) |
| 39 | projects.push(...result.nodes) |
| 40 | |
| 41 | if (!result.pageInfo.hasNextPage) { |
| 42 | return projects |
| 43 | } |
| 44 | after = result.pageInfo.endCursor ?? undefined |
| 45 | if (!after) { |
| 46 | return projects |
| 47 | } |
| 48 | if (page === MAX_PROJECTS_PAGES - 1) { |
| 49 | logger.warn('Linear projects pagination hit cap; project list may be incomplete', { |
| 50 | teamId: team.id, |
| 51 | cap: MAX_PROJECTS_PAGES, |
| 52 | fetched: projects.length, |
| 53 | }) |
| 54 | } |
| 55 | } |
| 56 | |
| 57 | return projects |
| 58 | } |
| 59 | |
| 60 | export const POST = withRouteHandler(async (request: NextRequest) => { |
| 61 | try { |