@@ -7,13 +7,28 @@ import {
7
7
} from "../sort-libraries/get-github-stats"
8
8
9
9
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
10
12
const CODE_DIR = new URL ( "../../src/code" , import . meta. url ) . pathname
11
13
12
14
async function main ( ) {
13
15
const filePaths = await fg ( "./**/*.md" , { cwd : CODE_DIR , absolute : true } )
14
16
15
17
const errors : Error [ ] = [ ]
16
18
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
+
17
32
const newState = new Map < string /* repo name */ , GitHubInfo > ( )
18
33
const filePathToRepoName = new Map <
19
34
string /* file path */ ,
@@ -82,6 +97,7 @@ async function main() {
82
97
}
83
98
84
99
await fs . writeFile ( DATA_PATH , JSON . stringify ( result , null , 2 ) )
100
+ await fs . writeFile ( LAST_RUN_PATH , new Date ( ) . toISOString ( ) )
85
101
}
86
102
}
87
103
0 commit comments