Skip to content

Commit 5106918

Browse files
committed
refactor(fetch-all): simplify pageId branch in fetchAllNotionData
- Skip applyFetchAllTransform in the single-page path: bulk-mode sorting, deduplication, and status-based child resolution are not needed for a single page retrieved directly by ID. Passing pageId+statusFilter no longer silently drops the page when statuses don't match. - Preserve includeRemoved guard: pages with status "Remove" are still filtered out when includeRemoved=false. - Remove dead candidateIds logic: only consumed by fetch-ready; return [] unconditionally. - Remove redundant defensivelyFiltered step that re-applied the same Remove filter already handled above.
1 parent 20fbf4c commit 5106918

File tree

1 file changed

+9
-22
lines changed

1 file changed

+9
-22
lines changed

scripts/notion-fetch-all/fetchAll.ts

Lines changed: 9 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -76,24 +76,17 @@ export async function fetchAllNotionData(
7676
generateOptions = {},
7777
} = options;
7878

79-
// Single-page fetch uses a direct page retrieval, then generation-only path
80-
// to avoid a full database query.
79+
// Single-page fetch uses a direct page retrieval, skips bulk-mode transforms,
80+
// then runs generation-only path to avoid a full database query.
8181
if (pageId) {
8282
const page = await notion.pages.retrieve({ page_id: pageId });
8383
const fetchedCount = 1;
84-
let candidateIds: string[] = [];
8584
const basePage = page as Record<string, unknown>;
8685

87-
if (statusFilter && getStatusFromRawPage(basePage) === statusFilter) {
88-
candidateIds = [(basePage as any).id];
89-
}
90-
91-
const transformedPages = applyFetchAllTransform([basePage], {
92-
statusFilter,
93-
maxPages,
94-
includeRemoved,
95-
});
96-
const rawData = Array.isArray(transformedPages) ? transformedPages : [];
86+
const rawData =
87+
!includeRemoved && getStatusFromRawPage(basePage) === "Remove"
88+
? []
89+
: [basePage];
9790

9891
let metrics: FetchAllResult["metrics"] | undefined;
9992
if (exportFiles) {
@@ -107,21 +100,15 @@ export async function fetchAllNotionData(
107100
metrics = generationResult.metrics;
108101
}
109102

110-
const defensivelyFiltered = rawData.filter((p) => {
111-
const status = getStatusFromRawPage(p);
112-
if (!includeRemoved && status === "Remove") return false;
113-
return true;
114-
});
115-
116-
const pages = defensivelyFiltered.map((rawPage) => transformPage(rawPage));
103+
const pages = rawData.map((rawPage) => transformPage(rawPage));
117104
const sortedPages = sortPages(pages, sortBy, sortDirection);
118105

119106
logStatusSummary(sortedPages);
120107

121108
return {
122109
pages: sortedPages,
123-
rawPages: defensivelyFiltered,
124-
candidateIds,
110+
rawPages: rawData,
111+
candidateIds: [],
125112
metrics,
126113
fetchedCount,
127114
processedCount: sortedPages.length,

0 commit comments

Comments
 (0)