pve-manager/www/manager6/data/PermPathStore.js
Thomas Lamprecht baed2b7c41 fix #2574: ui: permission-path selector: push each unique path only once
In clusters a storage was pushed as many times as there are nodes
using it. Ensure we only push a path once, do this with a memory
oriented solution, i.e., build a extra object to remember what we
already pushed. This is preferred over a me.findExact call as it's a
o(n) vs o(n^2) solution compute wise and we make the user wait if
this would need long, so reducing compute time over memory use is
here a good choice - even if we will seldom run into situations where
this actually will make a difference with such small data counts.

Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
2020-05-24 02:10:50 +02:00

54 lines
1.1 KiB
JavaScript

Ext.define('PVE.data.PermPathStore', {
extend: 'Ext.data.Store',
alias: 'store.pvePermPath',
fields: ['value'],
autoLoad: false,
data: [
{ 'value': '/' },
{ 'value': '/access' },
{ 'value': '/nodes' },
{ 'value': '/pool' },
{ 'value': '/storage' },
{ 'value': '/vms' },
],
constructor: function(config) {
var me = this;
config = config || {};
me.callParent([config]);
let donePaths = {};
me.suspendEvents();
PVE.data.ResourceStore.each(function(record) {
let path;
switch (record.get('type')) {
case 'node': path = '/nodes/' + record.get('text');
break;
case 'qemu': path = '/vms/' + record.get('vmid');
break;
case 'lxc': path = '/vms/' + record.get('vmid');
break;
case 'storage': path = '/storage/' + record.get('storage');
break;
case 'pool': path = '/pool/' + record.get('pool');
break;
}
if (path !== undefined && !donePaths[path]) {
me.add({ value: path });
donePaths[path] = 1;
}
});
me.resumeEvents();
me.fireEvent('refresh', me);
me.fireEvent('datachanged', me);
me.sort({
property: 'value',
direction: 'ASC',
});
},
});