Skip to content

:hedgehog: PostHog is the leading platform for building self-driving products. Our developer tools – AI observability, analytics, session replay, flags, experiments, error tracking, logs, and more – capture all the context agents need to diagnose problems, uncover opportunities, and ship fixes. Steer it all from Slack, web, desktop, or the MCP.

refactor(desktop): share the task list page size from the api client (#118069)

Paul D'Ambra8daf083ec217
diff --git a/products/desktop/packages/api-client/src/posthog-client.ts b/products/desktop/packages/api-client/src/posthog-client.ts
index 35cbda229ff7..9fd3f7ae3846 100644
--- a/products/desktop/packages/api-client/src/posthog-client.ts
+++ b/products/desktop/packages/api-client/src/posthog-client.ts
@@ -240,6 +240,8 @@ export const DESKTOP_BILLING_LIMIT_ERROR_CODE =
export const SESSION_LOGS_MAX_PAGE_SIZE = 5000;
export const SESSION_LOGS_PAGE_TIMEOUT_MS = 30_000;
+// The task list endpoint caps a page at this many rows (TasksPagination.max_limit).
+export const TASK_LIST_MAX_PAGE_SIZE = 100;
export interface TaskRunSessionLogsResult {
entries: StoredLogEntry[];
@@ -3268,7 +3270,10 @@ export class PostHogAPIClient {
const maxPages = pagination?.fetchAll
? Number.POSITIVE_INFINITY
: (pagination?.maxPages ?? 1);
- const pageSize = Math.min(options?.limit ?? 100, 100);
+ const pageSize = Math.min(
+ options?.limit ?? TASK_LIST_MAX_PAGE_SIZE,
+ TASK_LIST_MAX_PAGE_SIZE,
+ );
const tasks: Task[] = [];
let count = 0;
@@ -3397,7 +3402,6 @@ export class PostHogAPIClient {
// the largest page, then pull any remaining pages in parallel by offset. The
// old code walked `next` one blocking request at a time, so a large sidebar
// turned into a chain of serial round-trips on every inbox open.
- const PAGE_LIMIT = 100;
const MAX_PAGES = 50;
const teamId = await this.getTeamId();
const basePath = `/api/projects/${teamId}/tasks/summaries/`;
@@ -3405,7 +3409,7 @@ export class PostHogAPIClient {
const fetchPage = async (
offset: number,
): Promise<TaskSummariesResponse> => {
- const urlPath = `${basePath}?limit=${PAGE_LIMIT}&offset=${offset}`;
+ const urlPath = `${basePath}?limit=${TASK_LIST_MAX_PAGE_SIZE}&offset=${offset}`;
const response = await this.api.fetcher.fetch({
method: "post",
url: new URL(`${this.api.baseUrl}${urlPath}`),
@@ -3424,15 +3428,19 @@ export class PostHogAPIClient {
const first = await fetchPage(0);
const all: TaskSummaryDTO[] = [...first.results];
- const capped = Math.min(first.count, PAGE_LIMIT * MAX_PAGES);
- if (first.count > PAGE_LIMIT * MAX_PAGES) {
+ const capped = Math.min(first.count, TASK_LIST_MAX_PAGE_SIZE * MAX_PAGES);
+ if (first.count > TASK_LIST_MAX_PAGE_SIZE * MAX_PAGES) {
log.warn(
`getTaskSummaries capped at ${MAX_PAGES} pages; returning partial results`,
{ ids: ids.length, count: first.count },
);
}
const offsets: number[] = [];
- for (let offset = PAGE_LIMIT; offset < capped; offset += PAGE_LIMIT) {
+ for (
+ let offset = TASK_LIST_MAX_PAGE_SIZE;
+ offset < capped;
+ offset += TASK_LIST_MAX_PAGE_SIZE
+ ) {
offsets.push(offset);
}
// Cap how many page POSTs are in flight at once. A large sidebar can span
diff --git a/products/desktop/packages/ui/src/features/canvas/hooks/useRecentWorkItems.ts b/products/desktop/packages/ui/src/features/canvas/hooks/useRecentWorkItems.ts
index c4040f704ad4..26e31757304c 100644
--- a/products/desktop/packages/ui/src/features/canvas/hooks/useRecentWorkItems.ts
+++ b/products/desktop/packages/ui/src/features/canvas/hooks/useRecentWorkItems.ts
@@ -1,3 +1,4 @@
+import { TASK_LIST_MAX_PAGE_SIZE } from "@posthog/api-client/posthog-client";
import {
buildChannelItems,
type ChannelItemModel,
@@ -13,7 +14,6 @@ import { useAllCanvases } from "@posthog/ui/features/canvas/hooks/useDashboards"
import { useCanvasViewedStore } from "@posthog/ui/features/canvas/stores/canvasViewedStore";
import { usePinnedTasks } from "@posthog/ui/features/sidebar/usePinnedTasks";
import {
- TASK_LIST_MAX_PAGE_SIZE,
usePinnedTaskRecords,
useTasks,
} from "@posthog/ui/features/tasks/useTasks";
diff --git a/products/desktop/packages/ui/src/features/tasks/useTasks.ts b/products/desktop/packages/ui/src/features/tasks/useTasks.ts
index dbd0dce60bf1..cf28a4b44d8c 100644
--- a/products/desktop/packages/ui/src/features/tasks/useTasks.ts
+++ b/products/desktop/packages/ui/src/features/tasks/useTasks.ts
@@ -1,3 +1,4 @@
+import { TASK_LIST_MAX_PAGE_SIZE } from "@posthog/api-client/posthog-client";
import type { TaskSummaryDTO } from "@posthog/api-client/task-normalization";
import type { Task } from "@posthog/shared/domain-types";
import { keepPreviousData } from "@tanstack/react-query";
@@ -71,8 +72,6 @@ export function useTasks(
);
}
-export const TASK_LIST_MAX_PAGE_SIZE = 100;
-
/**
* Pinned records read every page on each poll, so the poll waits one interval per page. Any pin
* history then costs about one page request a minute and still refreshes.