Skip to content
This repository has been archived by the owner on Nov 25, 2020. It is now read-only.

Commit

Permalink
AjxpNode optimization: do not store children in Array but in Hash. Ma…
Browse files Browse the repository at this point in the history
…kes parseNodes() function much more quick, as findChildByPath() was called many times.

Remove disableTextSelection() calls in FileList for performances.
  • Loading branch information
cdujeu committed Sep 4, 2014
1 parent a6e29ac commit f969605
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 20 deletions.
2 changes: 1 addition & 1 deletion core/src/plugins/gui.ajax/res/js/ajaxplorer.js

Large diffs are not rendered by default.

34 changes: 21 additions & 13 deletions core/src/plugins/gui.ajax/res/js/ajaxplorer/class.AjxpNode.js
Expand Up @@ -41,7 +41,7 @@ Class.create("AjxpNode", {
this._isLeaf = isLeaf || false;
this._label = label || '';
this._icon = icon || '';
this._children = $A([]);
this._children = $H();
this._isRoot = false;

this._isLoaded = false;
Expand Down Expand Up @@ -95,8 +95,11 @@ Class.create("AjxpNode", {
* @param iAjxpNodeProvider IAjxpNodeProvider Optionnal
*/
reload : function(iAjxpNodeProvider){
this._children.each(function(child){
this.removeChild(child);
this._children.each(function(pair){
pair.value.notify("node_removed");
pair.value._parentNode = null;
this._children.unset(pair.key);
this.notify("child_removed", pair.value);
}.bind(this));
this._isLoaded = false;
this.load(iAjxpNodeProvider);
Expand All @@ -105,8 +108,11 @@ Class.create("AjxpNode", {
* Unload child and notify "force_clear"
*/
clear : function(){
this._children.each(function(child){
this.removeChild(child);
this._children.each(function(pair){
pair.value.notify("node_removed");
pair.value._parentNode = null;
this._children.unset(pair.key);
this.notify("child_removed", pair.value);
}.bind(this));
this._isLoaded = false;
this.notify("force_clear");
Expand All @@ -122,15 +128,18 @@ Class.create("AjxpNode", {
* @param ajxpNodes AjxpNodes[]
*/
setChildren : function(ajxpNodes){
this._children = $A(ajxpNodes);
this._children.invoke('setParent', this);
this._children = $H();
$A(ajxpNodes).each(function(n){
this._children.set(n.getPath(), n);
n.setParent(this);
}.bind(this));
},
/**
* Get all children as a bunch
* @returns AjxpNode[]
*/
getChildren : function(){
return this._children;
return this._children.values();
},
/**
* Adds a child to children
Expand All @@ -143,7 +152,7 @@ Class.create("AjxpNode", {
if(existingNode && !Object.isString(existingNode)){
existingNode.replaceBy(ajxpNode, "override");
}else{
this._children.push(ajxpNode);
this._children.set(ajxpNode.getPath(), ajxpNode);
this.notify("child_added", ajxpNode.getPath());
}
},
Expand All @@ -155,9 +164,10 @@ Class.create("AjxpNode", {
var removePath = ajxpNode.getPath();
ajxpNode.notify("node_removed");
ajxpNode._parentNode = null;
this._children = this._children.without(ajxpNode);
this._children.unset(ajxpNode.getPath());
this.notify("child_removed", removePath);
},

/**
* Replaces the current node by a new one. Copy all properties deeply
* @param ajxpNode AjxpNode
Expand Down Expand Up @@ -209,9 +219,7 @@ Class.create("AjxpNode", {
* @returns AjxpNode
*/
findChildByPath : function(path){
return $A(this._children).find(function(child){
return (child.getPath() == path);
});
return this._children.get(path);
},
/**
* Sets the metadata as a bunch
Expand Down
12 changes: 7 additions & 5 deletions core/src/plugins/gui.ajax/res/js/ajaxplorer/class.FilesList.js
Expand Up @@ -746,8 +746,8 @@ Class.create("FilesList", SelectableElements, {
this.getCurrentContextNode().reload();
}.bind(this), this.getVisibleColumns(), this.paginationData.get('currentOrderCol')||-1, this.paginationData.get('currentOrderDir') );
}
this.disableTextSelection(this.htmlElement.down('div.sort-table'), true);
this.disableTextSelection(contentContainer, true);
//this.disableTextSelection(this.htmlElement.down('div.sort-table'), true);
//this.disableTextSelection(contentContainer, true);
this.observer = function(e){
if(this.options.fit && this.options.fit == 'height') fitHeightToBottom(contentContainer, this.htmlElement);
if(Prototype.Browser.IE){
Expand Down Expand Up @@ -891,7 +891,7 @@ Class.create("FilesList", SelectableElements, {
});
}

this.disableTextSelection(scrollElement, true);
//this.disableTextSelection(scrollElement, true);
if(this.options.selectable == undefined || this.options.selectable === true){
this.initSelectableItems(scrollElement, true, scrollElement, true);
}else{
Expand Down Expand Up @@ -1175,11 +1175,13 @@ Class.create("FilesList", SelectableElements, {
this._headerResizer.resize(this.htmlElement.getWidth()-2);
}
}
/*
var allItems = this.getItems();
for(var i=0; i<allItems.length;i++)
{
this.disableTextSelection.bind(this).defer(allItems[i], true);
}
*/
this.notify("resize");
this.notify("rows:didInitialize");
},
Expand Down Expand Up @@ -1753,12 +1755,12 @@ Class.create("FilesList", SelectableElements, {
var date = new Date();
date.setTime(parseInt(metaData.get(s))*1000);
newRow.ajxp_modiftime = date;
tableCell.update('<span class="text_label'+fullview+'">' + formatDate(date) + '</span>');
tableCell.innerHTML = '<span class="text_label'+fullview+'">' + formatDate(date) + '</span>';
}
else
{
var metaValue = metaData.get(s) || "";
tableCell.update('<span class="text_label'+fullview+'">' + metaValue + "</span>");
tableCell.innerHTML = '<span class="text_label'+fullview+'">' + metaValue + "</span>";
}
if(this.gridStyle == "grid"){
tableCell.setAttribute('valign', 'top');
Expand Down
3 changes: 2 additions & 1 deletion core/src/plugins/gui.ajax/res/js/ajaxplorer_list.txt
Expand Up @@ -65,4 +65,5 @@ js/ajaxplorer/class.FormManager.js
js/ajaxplorer/class.DataModelProperty.js
js/ajaxplorer/class.MultiDownloader.js
js/ajaxplorer/class.ActivityMonitor.js
js/ajaxplorer/class.Ajaxplorer.js
js/ajaxplorer/class.Ajaxplorer.js
../../editor.ajxp_graphs/class.GraphsViewer.js

0 comments on commit f969605

Please sign in to comment.