]> git.proxmox.com Git - proxmox-widget-toolkit.git/blobdiff - src/Toolkit.js
override deselection in CheckboxModel to improve performance
[proxmox-widget-toolkit.git] / src / Toolkit.js
index f7060366b53ef1644c8c216431d3ee9daadccca9..79bc5ae3ffeef93164cb5f594a20dee64262cd4d 100644 (file)
@@ -152,8 +152,7 @@ Ext.apply(Ext.form.field.VTypes, {
                Proxmox.Utils.HostPortBrackets_match.test(v) ||
                Proxmox.Utils.IP6_dotnotation_match.test(v);
     },
-
-    HostPortText: gettext('Not a valid hosts'),
+    HostPortText: gettext('Host/IP address or optional port is invalid'),
 
     HostList: function(v) {
        let list = v.split(/[ ,;]+/);
@@ -493,11 +492,81 @@ Ext.define('Proxmox.validIdReOverride', {
     validIdRe: /^[a-z_][a-z0-9\-_@]*$/i,
 });
 
+Ext.define('Proxmox.selection.CheckboxModel', {
+    override: 'Ext.selection.CheckboxModel',
+
+    // [P] use whole checkbox cell to multiselect, not only the checkbox
+    checkSelector: '.x-grid-cell-row-checker',
+
+    // [ P: optimized to remove all records at once as single remove is O(n^3) slow ]
+    // records can be an index, a record or an array of records
+    doDeselect: function(records, suppressEvent) {
+        var me = this,
+            selected = me.selected,
+            i = 0,
+            len, record,
+            commit;
+        if (me.locked || !me.store) {
+            return false;
+        }
+        if (typeof records === "number") {
+            // No matching record, jump out
+            record = me.store.getAt(records);
+            if (!record) {
+                return false;
+            }
+            records = [
+                record,
+            ];
+        } else if (!Ext.isArray(records)) {
+            records = [
+                records,
+            ];
+        }
+       // [P] a beforedeselection, triggered by me.onSelectChange below, can block removal by
+       // returning false, thus the original implementation removed only here in the commit fn,
+       // which has an abysmal performance O(n^3). As blocking removal is not the norm, go do the
+       // reverse, record blocked records and remove them from the to-be-removed array before
+       // applying it. A FF86 i9-9900K on 10k records goes from >40s to ~33ms for >90% deselection
+       let committed = false;
+       commit = function() {
+           committed = true;
+           if (record === me.selectionStart) {
+               me.selectionStart = null;
+           }
+       };
+       let removalBlocked = [];
+        len = records.length;
+        me.suspendChanges();
+        for (; i < len; i++) {
+            record = records[i];
+            if (me.isSelected(record)) {
+               committed = false;
+                me.onSelectChange(record, false, suppressEvent, commit);
+               if (!committed) {
+                   removalBlocked.push(record);
+               }
+                if (me.destroyed) {
+                    return false;
+                }
+            }
+        }
+       if (removalBlocked.length > 0) {
+           records.remove(removalBlocked);
+       }
+       selected.remove(records); // [P] FAST(er)
+       me.lastSelected = selected.last();
+        me.resumeChanges();
+        // fire selchange if there was a change and there is no suppressEvent flag
+       me.maybeFireSelectionChange(records.length > 0 && !suppressEvent);
+       return records.length > 0;
+    },
+});
+
 // force alert boxes to be rendered with an Error Icon
 // since Ext.Msg is an object and not a prototype, we need to override it
 // after the framework has been initiated
 Ext.onReady(function() {
-/*jslint confusion: true */
     Ext.override(Ext.Msg, {
        alert: function(title, message, fn, scope) { // eslint-disable-line consistent-return
            if (Ext.isString(title)) {
@@ -514,7 +583,6 @@ Ext.onReady(function() {
            }
        },
     });
-/*jslint confusion: false */
 });
 Ext.define('Ext.ux.IFrame', {
     extend: 'Ext.Component',
@@ -615,7 +683,6 @@ Ext.define('Ext.ux.IFrame', {
                 // the event reaches listeners on elements like the document body. The effected
                 // mechanisms that depend on this bubbling behavior are listed to the right
                 // of the event.
-               /*jslint nomen: true*/
                 Ext.get(doc).on(
                     me._docListeners = {
                         mousedown: fn, // menu dismisal (MenuManager) and Window onMouseDown (toFront)
@@ -626,7 +693,6 @@ Ext.define('Ext.ux.IFrame', {
                         scope: me,
                     },
                 );
-               /*jslint nomen: false*/
             } catch (e) {
                 // cannot do this xss
             }