Skip to content

Commit

Permalink
Upgrades: add batch updates for larger upgrades when updating tens of…
Browse files Browse the repository at this point in the history
… thousands of jobs.
  • Loading branch information
michaelhoefer committed Aug 5, 2021
1 parent 06423c9 commit 3fb7ad4
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 3 deletions.
15 changes: 13 additions & 2 deletions api/orgpackageversions.js
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,18 @@ async function insertOrgPackageVersions(opvs) {
return db.insert(sql, values);
}

async function updateOrgPackageVersions(opvs) {
async function updateOrgPackageVersions(opvs, batchSize = 2000) {
const count = opvs.length;
for (let start = 0; start < count;) {
try {
await updateOrgPackageVersionsBatch(opvs.slice(start, start += batchSize));
} catch (e) {
logger.error(e);
}
}
}

async function updateOrgPackageVersionsBatch(opvs) {
let n = 0;
let params = [];
let values = [];
Expand Down Expand Up @@ -141,4 +152,4 @@ exports.findAll = findAll;
exports.insertOrgPackageVersions = insertOrgPackageVersions;
exports.updateOrgPackageVersions = updateOrgPackageVersions;
exports.updateFromLicenseStatus = updateFromLicenseStatus;
exports.updateStatus = updateStatus;
exports.updateStatus = updateStatus;
13 changes: 12 additions & 1 deletion api/upgrades.js
Original file line number Diff line number Diff line change
Expand Up @@ -457,7 +457,18 @@ async function updateUpgradeItemStatus(updated) {
await db.update(sql, values);
}

async function updateUpgradeJobsStatus(jobs) {
async function updateUpgradeJobsStatus(jobs, batchSize = 2000) {
const count = jobs.length;
for (let start = 0; start < count;) {
try {
await updateUpgradeJobsStatusBatch(jobs.slice(start, start += batchSize));
} catch (e) {
logger.error(e);
}
}
}

async function updateUpgradeJobsStatusBatch(jobs) {
let n = 0;
let params = [];
let values = [];
Expand Down

0 comments on commit 3fb7ad4

Please sign in to comment.