@@ -260,7 +260,6 @@ class DataProcessor {
260260 this . commits = [ ] ;
261261 this . checks = { } ;
262262 this . runs = { } ;
263- this . artifacts = { } ;
264263 }
265264
266265 readExistingData ( existingData ) {
@@ -273,8 +272,54 @@ class DataProcessor {
273272 if ( typeof existingData . runs !== "undefined" ) {
274273 this . runs = existingData . runs ;
275274 }
276- if ( typeof existingData . artifacts !== "undefined" ) {
277- this . artifacts = existingData . artifacts ;
275+ }
276+
277+ reduceData ( ) {
278+ // The goal is to display only the most recent commits and their artifacts.
279+ // However, we can't just always fetch the last N commits and be done with
280+ // it. Fetched commits can still be in progress, and we want to have at least
281+ // some version available.
282+
283+ // Note that artifacts expire, so it is still possible to have none. But we
284+ // should at least try.
285+
286+ const MAX_COMMITS = 20 ;
287+
288+ // Determine which commits are the latest available with ready builds.
289+ const latestArtifacts = this . getLatestArtifacts ( ) ;
290+ const latestCommits = [ ] ;
291+ for ( let artifactName in latestArtifacts ) {
292+ const artifactCommit = latestArtifacts [ artifactName ] . commit_hash ;
293+ if ( latestCommits . indexOf ( artifactCommit ) < 0 ) {
294+ latestCommits . push ( artifactCommit ) ;
295+ }
296+ }
297+
298+ for ( let i = 0 ; i < this . commits . length ; i ++ ) {
299+ const commit = this . commits [ i ] ;
300+ const commitIndex = latestCommits . indexOf ( commit . hash ) ;
301+ if ( commitIndex >= 0 ) {
302+ latestCommits . splice ( commitIndex , 1 ) ;
303+ }
304+
305+ // We want to have at least MAX_COMMITS commits; and we also want to
306+ // hit every commit contributing to the latest artifacts.
307+ if ( i < MAX_COMMITS || latestCommits . length > 0 ) {
308+ continue ;
309+ }
310+
311+ // But beyond that, cut it all out.
312+ console . log ( ` Removed extra commit ${ commit . hash } .` ) ;
313+
314+ this . commits . splice ( i , 1 ) ;
315+ for ( let checkId of commit . checks ) {
316+ const check = this . checks [ checkId ] ;
317+ delete this . checks [ checkId ] ;
318+
319+ if ( check . workflow !== "" ) {
320+ delete this . runs [ check . workflow ] ;
321+ }
322+ }
278323 }
279324 }
280325
@@ -322,7 +367,7 @@ class DataProcessor {
322367 } else {
323368 check . status = checkItem . status ;
324369 check . conclusion = checkItem . conclusion ;
325- check . updatedAt = checkItem . updatedAt ;
370+ check . updated_at = checkItem . updatedAt ;
326371 }
327372
328373 if ( check . workflow === "" && checkItem . workflowRun ) {
@@ -611,10 +656,12 @@ async function main() {
611656 await dataFetcher . delay ( API_DELAY_MSEC ) ;
612657 }
613658
614- console . log ( "[*] Checking the rate limits after." )
659+ console . log ( "[*] Checking the rate limits after." ) ;
615660 await dataFetcher . checkRates ( ) ;
616661 checkForExit ( ) ;
617662
663+ console . log ( "[*] Reducing database." ) ;
664+ dataProcessor . reduceData ( ) ;
618665 const latestArtifacts = dataProcessor . getLatestArtifacts ( ) ;
619666
620667 console . log ( "[*] Finalizing database." )
@@ -623,7 +670,6 @@ async function main() {
623670 "commits" : dataProcessor . commits ,
624671 "checks" : dataProcessor . checks ,
625672 "runs" : dataProcessor . runs ,
626- "artifacts" : dataProcessor . artifacts ,
627673 "latest" : latestArtifacts ,
628674 } ;
629675
0 commit comments