From 6c5fdf176de2e405f0f60412cbabd1ef505b0c26 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=90=8C=E8=90=8C=E5=93=92=E8=B5=AB=E8=90=9D?= Date: Fri, 14 Apr 2023 21:38:15 +0800 Subject: [PATCH] :zap: Perf: optimize imgur album list speed --- src/main/manage/apis/imgur.ts | 29 +++++++++-------------------- 1 file changed, 9 insertions(+), 20 deletions(-) diff --git a/src/main/manage/apis/imgur.ts b/src/main/manage/apis/imgur.ts index ff102d98..2e673742 100644 --- a/src/main/manage/apis/imgur.ts +++ b/src/main/manage/apis/imgur.ts @@ -60,35 +60,24 @@ class ImgurApi { const result = [] as any[] do { res = await got( - `${this.baseUrl}/account/${this.userName}/albums/ids/${initPage}`, + `${this.baseUrl}/account/${this.userName}/albums/${initPage}`, getOptions('GET', this.tokenHeaders, undefined, 'json', undefined, undefined, this.proxy) ) as any - if (res.statusCode === 200 && res.body.success) { - res.body.data.forEach((item: any) => { - result.push(item) - }) - } else { + if (!(res.statusCode === 200 && res.body.success)) { return [] } + result.push(...res.body.data) initPage++ } while (res.body.data.length > 0) const finalResult = [] as any[] for (let i = 0; i < result.length; i++) { const item = result[i] - const res = await got( - `${this.baseUrl}/account/${this.userName}/album/${item}`, - getOptions('GET', this.tokenHeaders, undefined, 'json', undefined, undefined, this.proxy) - ) as any - if (res.statusCode === 200 && res.body.success) { - finalResult.push({ - ...res.body.data, - Name: res.body.data.title, - Location: res.body.data.id, - CreationDate: res.body.data.datetime - }) - } else { - return [] - } + finalResult.push({ + ...item, + Name: item.title, + Location: item.id, + CreationDate: item.datetime + }) } finalResult.push({ Name: '全部',