From d189e7bae00459190084e4b0129b4462eefdcc10 Mon Sep 17 00:00:00 2001 From: wxiaoguang Date: Mon, 15 Nov 2021 23:19:40 +0800 Subject: [PATCH 1/2] Fix database deadlock when update issue labels --- web_src/js/features/repo-issue.js | 24 ++++++++++-------------- web_src/js/features/repo-legacy.js | 23 +++++++++++------------ 2 files changed, 21 insertions(+), 26 deletions(-) diff --git a/web_src/js/features/repo-issue.js b/web_src/js/features/repo-issue.js index 782957c5b16c3..b69ba2571978c 100644 --- a/web_src/js/features/repo-issue.js +++ b/web_src/js/features/repo-issue.js @@ -332,20 +332,16 @@ export function initRepoIssueWipTitle() { }); } -export function updateIssuesMeta(url, action, issueIds, elementId) { - return new Promise((resolve, reject) => { - $.ajax({ - type: 'POST', - url, - data: { - _csrf: csrfToken, - action, - issue_ids: issueIds, - id: elementId, - }, - success: resolve, - error: reject, - }); +export async function updateIssuesMeta(url, action, issueIds, elementId) { + return $.ajax({ + type: 'POST', + url, + data: { + _csrf: csrfToken, + action, + issue_ids: issueIds, + id: elementId, + }, }); } diff --git a/web_src/js/features/repo-legacy.js b/web_src/js/features/repo-legacy.js index 8945360cd5804..50b3f5d66e08c 100644 --- a/web_src/js/features/repo-legacy.js +++ b/web_src/js/features/repo-legacy.js @@ -84,18 +84,17 @@ export function initRepoCommentForm() { $(`.${selector}`).dropdown('setting', 'onHide', () => { hasUpdateAction = $listMenu.data('action') === 'update'; // Update the var if (hasUpdateAction) { - const promises = []; - Object.keys(items).forEach((elementId) => { - const item = items[elementId]; - const promise = updateIssuesMeta( - item['update-url'], - item.action, - item['issue-id'], - elementId, - ); - promises.push(promise); - }); - Promise.all(promises).then(() => window.location.reload()); + (async function() { + for (const [elementId, item] of Object.entries(items)) { + await updateIssuesMeta( + item['update-url'], + item.action, + item['issue-id'], + elementId, + ); + } + window.location.reload(); + })(); } }); From b8c57f160317c918ed9e38e9e91969ff385703b9 Mon Sep 17 00:00:00 2001 From: wxiaoguang Date: Mon, 15 Nov 2021 23:30:21 +0800 Subject: [PATCH 2/2] Update web_src/js/features/repo-legacy.js Co-authored-by: Gusted --- web_src/js/features/repo-legacy.js | 1 + 1 file changed, 1 insertion(+) diff --git a/web_src/js/features/repo-legacy.js b/web_src/js/features/repo-legacy.js index 50b3f5d66e08c..74880c5dc774b 100644 --- a/web_src/js/features/repo-legacy.js +++ b/web_src/js/features/repo-legacy.js @@ -84,6 +84,7 @@ export function initRepoCommentForm() { $(`.${selector}`).dropdown('setting', 'onHide', () => { hasUpdateAction = $listMenu.data('action') === 'update'; // Update the var if (hasUpdateAction) { + // TODO: Add batch functionality and make this 1 network request. (async function() { for (const [elementId, item] of Object.entries(items)) { await updateIssuesMeta(