]> source.dussan.org Git - gitea.git/commitdiff
Fix database deadlock when update issue labels (#17649)
authorwxiaoguang <wxiaoguang@gmail.com>
Tue, 16 Nov 2021 02:21:13 +0000 (10:21 +0800)
committerGitHub <noreply@github.com>
Tue, 16 Nov 2021 02:21:13 +0000 (10:21 +0800)
This fix updates issue labels one by one, and won't cause database deadlock.
In future, we can use a batch API to update all changed labels by one request.

web_src/js/features/repo-issue.js
web_src/js/features/repo-legacy.js

index 782957c5b16c3928b0d216c9df85d146a3e8d57d..b69ba2571978c1de5818dadf2125e12a2ef94fb0 100644 (file)
@@ -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,
+    },
   });
 }
 
index 8945360cd5804950a9fcb084d312ea04dadd5e2e..74880c5dc774bf0854216d4119582e5945e85d05 100644 (file)
@@ -84,18 +84,18 @@ 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());
+        // TODO: Add batch functionality and make this 1 network request.
+        (async function() {
+          for (const [elementId, item] of Object.entries(items)) {
+            await updateIssuesMeta(
+              item['update-url'],
+              item.action,
+              item['issue-id'],
+              elementId,
+            );
+          }
+          window.location.reload();
+        })();
       }
     });