]> git.proxmox.com Git - pmg-gui.git/blobdiff - js/SpamQuarantine.js
quarantine: restore behavior of selecting next in list after action
[pmg-gui.git] / js / SpamQuarantine.js
index 9a8464922d6690ae0c2ac348bf566c576b376c9c..f580ab3cf468f922a187c5273b6396a72f855b3a 100644 (file)
@@ -125,21 +125,45 @@ Ext.define('PMG.SpamQuarantine', {
                        gettext("Action '{0}' for '{1}' items"),
                        action, selected.length,
                    ),
-                   function(button) {
+                   async function(button) {
                        if (button !== 'yes') {
                            return;
                        }
 
-                       PMG.Utils.doQuarantineAction(action, idlist.join(';'), function() {
-                           list.getController().load();
-                       });
+                       list.mask(gettext('Processing...'), 'x-mask-loading');
+
+                       const sliceSize = 2500, maxInFlight = 2;
+                       let batches = [], batchCount = Math.ceil(selected.length / sliceSize);
+                       for (let i = 0; i * sliceSize < selected.length; i++) {
+                           let sliceStart = i * sliceSize;
+                           let sliceEnd = Math.min(sliceStart + sliceSize, selected.length);
+                           batches.push(
+                               PMG.Async.doQAction(
+                                   action,
+                                   idlist.slice(sliceStart, sliceEnd),
+                                   i + 1,
+                                   batchCount,
+                               ),
+                           );
+                           if (batches.length >= maxInFlight) {
+                               await Promise.allSettled(batches); // eslint-disable-line no-await-in-loop
+                               batches = [];
+                           }
+                       }
+                       await Promise.allSettled(batches); // await possible remaining ones
+                       list.unmask();
+                       // below can be slow, we could remove directly from the in-memory store, but
+                       // with lots of elements and some failures we could be quite out of sync?
+                       list.getController().load();
                    },
                );
                return;
            }
 
            PMG.Utils.doQuarantineAction(action, selected[0].data.id, function() {
-               list.getController().load();
+               // success -> remove directly to avoid slow store reload for a single-element action
+               list.getStore().remove(selected[0]);
+               list.getController().restoreSavedSelection();
            });
        },
 
@@ -168,15 +192,11 @@ Ext.define('PMG.SpamQuarantine', {
 
        openContextMenu: function(table, record, tr, index, event) {
            event.stopEvent();
-           var me = this;
-           var list = me.lookup('list');
-           var menu = Ext.create('PMG.menu.SpamContextMenu', {
-               callback: function(action) {
-                   me.doAction(action, list.getSelection());
-               },
-           });
-
-           menu.showAt(event.getXY());
+           let me = this;
+           let list = me.lookup('list');
+           Ext.create('PMG.menu.SpamContextMenu', {
+               callback: action => me.doAction(action, list.getSelection()),
+           }).showAt(event.getXY());
        },
 
        keyPress: function(table, record, item, index, event) {