return;
}
- var url = '/api2/htmlmail/quarantine/content?id=' + rec.data.id + (raw?'&raw=1':'');
+ let url = `/api2/htmlmail/quarantine/content?id=${rec.data.id}`;
+ if (raw) {
+ url += '&raw=1';
+ }
preview.setDisabled(false);
this.lookupReference('raw').setDisabled(false);
this.lookupReference('spam').setDisabled(false);
var list = this.lookupReference('list');
if (selected.length > 1) {
- var idlist = [];
- selected.forEach(function(item) {
- idlist.push(item.data.id);
- });
+ let idlist = selected.map(item => item.data.id);
Ext.Msg.confirm(
gettext('Confirm'),
Ext.String.format(
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();
+ let listController = list.getController();
+ listController.allowPositionSave = false;
+ // success -> remove directly to avoid slow store reload for a single-element action
+ list.getStore().remove(selected[0]);
+ listController.restoreSavedSelection();
+ listController.allowPositionSave = true;
});
},
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) {
title: gettext('Selected Mail'),
border: false,
region: 'center',
+ layout: 'fit',
split: true,
reference: 'preview',
disabled: true,