Skip to content

Commit 2565be2

Browse files
snomiaoclaude
andcommitted
fix(notion/people): use shared cached client, trim values, reset cache on failure
- Switch to the shared `notion` client from @/lib so responses hit Keyv cache. - Trim rich_text values at parse time; whitespace-only entries are now skipped. - Reset the module-level cache on rejection so transient failures can retry. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent 3def283 commit 2565be2

1 file changed

Lines changed: 13 additions & 12 deletions

File tree

lib/notion/people.ts

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
#!/usr/bin/env bun
2-
import { Client } from "@notionhq/client";
3-
import DIE from "@snomiao/die";
2+
import { notion } from "@/lib";
43
import yaml from "yaml";
54
import yargs from "yargs";
65
import { hideBin } from "yargs/helpers";
@@ -20,20 +19,20 @@ let peopleMappingsCache: Promise<PersonMapping[]> | null = null;
2019

2120
/**
2221
* Fetch all person mappings from the Notion People database.
23-
* Results are cached for the lifetime of the process.
22+
* Successful results are cached for the lifetime of the process.
23+
* Failed fetches are not cached, so later calls can retry.
2424
*/
2525
export function fetchPeopleMappings(): Promise<PersonMapping[]> {
2626
if (!peopleMappingsCache) {
27-
peopleMappingsCache = fetchPeopleMappingsUncached();
27+
peopleMappingsCache = fetchPeopleMappingsUncached().catch((error) => {
28+
peopleMappingsCache = null;
29+
throw error;
30+
});
2831
}
2932
return peopleMappingsCache;
3033
}
3134

3235
async function fetchPeopleMappingsUncached(): Promise<PersonMapping[]> {
33-
const notion = new Client({
34-
auth: process.env.NOTION_TOKEN || DIE("missing env.NOTION_TOKEN"),
35-
});
36-
3736
const results: PersonMapping[] = [];
3837
let cursor: string | undefined;
3938

@@ -52,14 +51,16 @@ async function fetchPeopleMappingsUncached(): Promise<PersonMapping[]> {
5251
(props?.["Person"]?.people as Array<{ name: string }> | undefined)
5352
?.map((p) => p.name)
5453
.join(", ") || "";
55-
const githubUsername =
54+
const githubUsername = (
5655
(props?.["GitHub Username"]?.rich_text as Array<{ plain_text: string }> | undefined)
5756
?.map((t) => t.plain_text)
58-
.join("") || "";
59-
const slackId =
57+
.join("") || ""
58+
).trim();
59+
const slackId = (
6060
(props?.["SlackID"]?.rich_text as Array<{ plain_text: string }> | undefined)
6161
?.map((t) => t.plain_text)
62-
.join("") || "";
62+
.join("") || ""
63+
).trim();
6364
const inactive = (props?.["Inactive"]?.checkbox as boolean) || false;
6465

6566
results.push({ person, githubUsername, slackId, inactive });

0 commit comments

Comments
 (0)