Skip to content

Commit

Permalink
feat: 优化远程片段获取的并发请求
Browse files Browse the repository at this point in the history
  • Loading branch information
geekdada committed Nov 14, 2019
1 parent 3e3dabc commit 7552fa0
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions lib/utils/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import assert from 'assert';
import axios from 'axios';
import Bluebird from 'bluebird';
import chalk from 'chalk';
import fs from 'fs-extra';
import _ from 'lodash';
Expand Down Expand Up @@ -1137,7 +1138,7 @@ export const loadRemoteSnippetList = (remoteSnippetList: ReadonlyArray<RemoteSni
});
}

return Promise.all(remoteSnippetList.map<Promise<RemoteSnippet>>(item => {
return Bluebird.map(remoteSnippetList, item => {
const res = ConfigCache.has(item.url)
? Promise.resolve(ConfigCache.get(item.url)) :
load(item.url)
Expand All @@ -1152,7 +1153,9 @@ export const loadRemoteSnippetList = (remoteSnippetList: ReadonlyArray<RemoteSni
url: item.url,
text: str, // 原始内容
}));
}));
}, {
concurrency: 5,
});
};

export const ensureConfigFolder = (dir: string = os.homedir()): string => {
Expand Down

0 comments on commit 7552fa0

Please sign in to comment.