Skip to content

Commit

Permalink
Improve loading speed of the CI/CD page
Browse files Browse the repository at this point in the history
Improve loading speed of the CI/CD page.
Only request the necessary fields from Jenkins to keep the request size low.
In addition everything is loaded in a single request, instead of requesting
each job and build individually. As this (and also the previous behavior) can
lead to a big amount of data, this limits the amount of jobs to 50.
For each job, only the latest build is loaded. Loading the full build history
of a job can lead to excessive load on the Jenkins instance.
  • Loading branch information
Fox32 committed Dec 4, 2020
1 parent 8225c58 commit 0f88771
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 13 deletions.
11 changes: 11 additions & 0 deletions .changeset/purple-radios-complain.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
---
'@backstage/plugin-jenkins': patch
---

Improve loading speed of the CI/CD page.
Only request the necessary fields from Jenkins to keep the request size low.
In addition everything is loaded in a single request, instead of requesting
each job and build individually. As this (and also the previous behavior) can
lead to a big amount of data, this limits the amount of jobs to 50.
For each job, only the latest build is loaded. Loading the full build history
of a job can lead to excessive load on the Jenkins instance.
48 changes: 35 additions & 13 deletions plugins/jenkins/src/api/JenkinsApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -107,26 +107,48 @@ export class JenkinsApi {

async getFolder(folderName: string) {
const client = await this.getClient();
const folder = await client.job.get(folderName);
const folder = await client.job.get({
name: folderName,
// Filter only be the information we need, instead of loading all fields.
// Limit to only show the latest build for each job and only load 50 jobs
// at all.
// Whitespaces are only included for readablity here and stripped out
// before sending to Jenkins
tree: `jobs[
actions[*],
builds[
number,
url,
fullDisplayName,
building,
result,
actions[
*[
*[
*[
*
]
]
]
]
]{0,1},
jobs{0,1},
name
]{0,50}
`.replace(/\s/g, ''),
});
const results = [];
for (const jobSummary of folder.jobs) {
const jobDetails = await client.job.get({
name: `${folderName}/${jobSummary.name}`,
depth: 1,
});

for (const jobDetails of folder.jobs) {
const jobScmInfo = this.extractScmDetailsFromJob(jobDetails);
if (jobDetails.jobs) {
// skipping folders inside folders for now
} else {
for (const buildDetails of jobDetails.builds) {
const build = await client.build.get({
name: `${folderName}/${jobSummary.name}`,
number: buildDetails.number,
depth: 1,
});

const ciTable = this.mapJenkinsBuildToCITable(build, jobScmInfo);
const ciTable = this.mapJenkinsBuildToCITable(
buildDetails,
jobScmInfo,
);
results.push(ciTable);
}
}
Expand Down

0 comments on commit 0f88771

Please sign in to comment.