@@ -7,13 +7,28 @@ import {
77} from "../sort-libraries/get-github-stats"
88
99const 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
1012const CODE_DIR = new URL ( "../../src/code" , import . meta. url ) . pathname
1113
1214async 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