Improve the performance of cronSyncArtifact

This commit is contained in:
Peng-YM 2022-04-30 11:29:07 +08:00
parent 4dc40e92ae
commit 7b68f9fa85
2 changed files with 9 additions and 4 deletions

View File

@ -660,7 +660,8 @@ function service() {
const allArtifacts = $.read(ARTIFACTS_KEY); const allArtifacts = $.read(ARTIFACTS_KEY);
let success = [], let success = [],
failed = []; failed = [];
for (const artifact of Object.values(allArtifacts)) {
await Promise.all(Object.values(allArtifacts).map(async artifact => {
if (artifact.sync) { if (artifact.sync) {
$.info(`正在同步云配置:${artifact.name}...`); $.info(`正在同步云配置:${artifact.name}...`);
try { try {
@ -687,10 +688,13 @@ function service() {
}); });
artifact.updated = new Date().getTime(); artifact.updated = new Date().getTime();
const body = JSON.parse(resp.body); const body = JSON.parse(resp.body);
// extract real url from gist
artifact.url = body.files[artifact.name].raw_url.replace( artifact.url = body.files[artifact.name].raw_url.replace(
/\/raw\/[^\/]*\/(.*)/, /\/raw\/[^\/]*\/(.*)/,
"/raw/$1" "/raw/$1"
); );
$.write(allArtifacts, ARTIFACTS_KEY); $.write(allArtifacts, ARTIFACTS_KEY);
$.info(`✅ 成功同步云配置:${artifact.name}`); $.info(`✅ 成功同步云配置:${artifact.name}`);
success.push(artifact); success.push(artifact);
@ -704,7 +708,8 @@ function service() {
failed.push(artifact); failed.push(artifact);
} }
} }
} }));
res.json({ res.json({
success, success,
failed, failed,

File diff suppressed because one or more lines are too long