Skip to content

Commit 88597a6

Browse files
committed
Add a limit to the amount of stored data
1 parent a896d2d commit 88597a6

2 files changed

Lines changed: 75 additions & 6 deletions

File tree

.github/workflows/ci.yml

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,11 @@ jobs:
2121
steps:
2222
- uses: actions/checkout@v3
2323

24+
- name: Checkout published data
25+
uses: actions/checkout@v3
26+
ref: gh-pages
27+
path: out
28+
2429
- name: Install Node.js 16.x
2530
uses: actions/setup-node@v3
2631
with:
@@ -39,6 +44,24 @@ jobs:
3944
GRAPHQL_TOKEN: ${{ secrets.GRAPHQL_TOKEN }}
4045
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
4146

47+
- name: Fetch artifact data (4.0)
48+
run: npm run compose-db -- branch:4.0
49+
env:
50+
GRAPHQL_TOKEN: ${{ secrets.GRAPHQL_TOKEN }}
51+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
52+
53+
- name: Fetch artifact data (3.x)
54+
run: npm run compose-db -- branch:3.x
55+
env:
56+
GRAPHQL_TOKEN: ${{ secrets.GRAPHQL_TOKEN }}
57+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
58+
59+
- name: Fetch artifact data (3.5)
60+
run: npm run compose-db -- branch:3.5
61+
env:
62+
GRAPHQL_TOKEN: ${{ secrets.GRAPHQL_TOKEN }}
63+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
64+
4265
- name: Archive production artifacts
4366
uses: actions/upload-artifact@v3
4467
with:

compose-db.js

Lines changed: 52 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)