Skip to content

Commit 567bf7f

Browse files
committed
Don't repeat GitHub star syncs more often than every two hours
1 parent 196cf25 commit 567bf7f

File tree

6 files changed

+491
-467
lines changed

6 files changed

+491
-467
lines changed

.prettierignore

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,4 @@ pnpm-lock.yaml
99
!src/pages/blog/2025-06-19-multioption-inputs-with-oneof/index.mdx
1010
*.jpg
1111

12-
scripts/sync-sched/*.json
13-
src/github-stats.json
12+
scripts/**/*.json

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
"lint:docs": "eslint --ignore-path .gitignore src/pages/learn --format stylish",
1616
"lint:docs:ci": "eslint --ignore-path .gitignore src/pages/learn --format eslint-formatter-github",
1717
"postbuild": "next-sitemap",
18-
"prebuild": "tsx src/get-github-info.ts",
18+
"prebuild": "tsx scripts/get-github-info",
1919
"serve": "pnpx serve out",
2020
"test": "playwright test && pnpm test:unit",
2121
"test:e2e": "playwright test",

scripts/get-github-info/get-github-info.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,28 @@ import {
77
} from "../sort-libraries/get-github-stats"
88

99
const DATA_PATH = new URL("./github-stats.json", import.meta.url).pathname
10+
const LAST_RUN_PATH = new URL("./last-success.isodate", import.meta.url)
11+
.pathname
1012
const CODE_DIR = new URL("../../src/code", import.meta.url).pathname
1113

1214
async function main() {
1315
const filePaths = await fg("./**/*.md", { cwd: CODE_DIR, absolute: true })
1416

1517
const errors: Error[] = []
1618

19+
{
20+
// we only sync once every two hours
21+
const TWO_HOURS = 2 * 60 * 60 * 1000
22+
const lastRun = await fs.readFile(LAST_RUN_PATH, "utf8").catch(() => "")
23+
const twoHoursAgo = new Date(Date.now() - TWO_HOURS)
24+
if (lastRun && new Date(lastRun).getTime() > twoHoursAgo.getTime()) {
25+
console.info(
26+
"Skipping sync of GitHub stars, last run was within two hours.",
27+
)
28+
return
29+
}
30+
}
31+
1732
const newState = new Map<string /* repo name */, GitHubInfo>()
1833
const filePathToRepoName = new Map<
1934
string /* file path */,
@@ -82,6 +97,7 @@ async function main() {
8297
}
8398

8499
await fs.writeFile(DATA_PATH, JSON.stringify(result, null, 2))
100+
await fs.writeFile(LAST_RUN_PATH, new Date().toISOString())
85101
}
86102
}
87103

0 commit comments

Comments
 (0)