Commit 8c190d25 authored by Pedro Eduardo Trujillo's avatar Pedro Eduardo Trujillo
Browse files

Soluciona carga exagerada para listado jerárquico

Debido al arreglo introducido en 1a1f7384, el tiempo de carga de los
listados jerárquicos tras recibir los datos era demasiado largo. El
motivo es que se estaba intentando dibujar las filas padre pendientes
tras la inserción de cada elemento (tanto si venía uno como si llegaba
un grupo de ellos). Ahora se diferencia ambos casos para no repetir
inútilmente el proceso.

Evalua la definición del módulo Row (y sus componentes) al principio, en
lugar de hacerlo a cada llegada de datos. Es inútil repetir el proceso
cuando esa definición no cambia desde la construcción del listado.

Reubica métodos repetidos (copy&paste) en diferentes implementaciones y
extensiones, definiéndolos una única vez.

Aprovecha para renombrar varios métodos bautizados de forma vaga y poco
concreta, así como corregir otros nombres con erratas.
parent a0b3c1ab
Loading
Loading
Loading
Loading
+26 −15
Original line number Diff line number Diff line
@@ -71,7 +71,7 @@ define([
				idProperty: 'id',
				_rows: {},

				definitionRow: [Row],
				_rowDefinitionComponents: [Row],

				initialDataSave: false
			};
@@ -163,6 +163,7 @@ define([
		postCreate: function() {

			this._createBrowserContainer();
			this._definitionRow();

			this.inherited(arguments);
		},
@@ -287,13 +288,9 @@ define([

		_addRow: function(idProperty, item) {

			var rowInstance;

			this._definitionRow();

			this._configRow(item);

			rowInstance = new declare(this._defRow)(this.rowConfig);
			var rowInstance = new declare(this._defRow)(this.rowConfig);

			this._setRow(idProperty, {
				instance: rowInstance,
@@ -303,17 +300,11 @@ define([

		_definitionRow: function() {

			this._defRow = [];

			this._defRow = lang.clone(this.definitionRow);

			if (this._defRow instanceof Array) {
				return this._defRow;
			}
			this._defRow = this._rowDefinitionComponents;

			if (!(this._defRow instanceof Array)) {
				this._defRow = [this._defRow];

			return this._defRow;
			}
		},

		_configRow: function(item) {
@@ -475,6 +466,26 @@ define([
			}

			return true;
		},

		_parserIndexData: function(response) {

			var data = response.data;

			if (data.data) {
				data = data.data;
			}

			return data;
		},

		_processNewData: function(response) {

			var data = this._parserIndexData(response);

			for (var i = 0; i < data.length; i++) {
				this._addItem(data[i]);
			}
		}
	});
});
+20 −42
Original line number Diff line number Diff line
@@ -58,9 +58,10 @@ define([
			aspect.after(this, "_definitionRow", lang.hitch(this, this._definitionHierarchicalRow));
			aspect.before(this, "_configRow", lang.hitch(this, this._configHierarchicalRow));

			aspect.before(this, "_addData", lang.hitch(this, this._addBeforeData));
			aspect.after(this, "_addData", lang.hitch(this, this._showPendingParents));
			aspect.after(this, "_addItem", lang.hitch(this, this._showPendingParents));
			aspect.before(this, "_dataAvailable", lang.hitch(this, this._beforeDataOrItemAvailable));
			aspect.before(this, "_itemAvailable", lang.hitch(this, this._beforeDataOrItemAvailable));
			aspect.after(this, "_dataAvailable", lang.hitch(this, this._afterDataOrItemAvailable));
			aspect.after(this, "_itemAvailable", lang.hitch(this, this._afterDataOrItemAvailable));

			aspect.before(this, "_removeRow", lang.hitch(this, this._removeHierarchicalRow));
		},
@@ -176,38 +177,21 @@ define([
			this._emitEvt('COLLAPSE_ROW', req);
		},

		_addBeforeData: function(response) {
		_beforeDataOrItemAvailable: function(response) {

			this._pendingParentsToShow = [];
		},

		_addData: function(response) {

			this._clearData();

			this._proccesNewData(response);
		},
		_afterDataOrItemAvailable: function(response) {

		_parserIndexData: function(response) {

			var data = response.data;

			if (data.data) {
				data = data.data;
			}

			return data;
			this._showPendingParents();
		},

		_proccesNewData: function(response) {

			var data = this._parserIndexData(response);
		_addData: function(response) {

			for (var i = 0; i < data.length; i++) {
				var item = data[i];
			this._clearData();

				this._addItem(item);
			}
			this._processNewData(response);
		},

		_addItem: function(item) {
@@ -215,7 +199,7 @@ define([
			var idProperty = item[this.idProperty],
				rowInstance = this._getRowInstance(idProperty);

			if (!this._getRowInstance(idProperty)) {
			if (!rowInstance) {
				this._addRowItem(item);
			} else {
				this._updateRow(rowInstance, item);
@@ -230,7 +214,7 @@ define([

			this._checkParentAndAddChild(item);

			if (this._evaluateItem(item)) {
			if (this._checkItemBelongRootLevel(item)) {
				this._addRow(idProperty, item);
			} else {
				this._addItemWithoutInstance(idProperty, item);
@@ -249,7 +233,7 @@ define([
				template: this._getTemplate(item)
			});

			if (!this._evaluateItem(item)) {
			if (!this._checkItemBelongRootLevel(item)) {
				this._publish(rowInstance.getChannel('UPDATE_DATA'), {
					data: item
				});
@@ -261,14 +245,12 @@ define([
			var idProperty = item[this.idProperty],
				rowInstance = this._getRowInstance(idProperty);

			if (!rowInstance || !this._evaluateItem(item)) {
			if (!rowInstance || !this._checkItemBelongRootLevel(item)) {
				return;
			} else if (item[this.leavesProperty]) {
				if (!this._pendingParentsToShow) {
					this._pendingParentsToShow = [];
			}
				this._pendingParentsToShow.push(idProperty);

			if (item[this.leavesProperty]) {
				this._pendingParentsToShow.push(idProperty);
				return;
			}

@@ -315,17 +297,13 @@ define([
			this._showInstanceRow(instance, item, this.rowsContainerNode, true);
		},

		_evaluateItem: function(item) {
		_checkItemBelongRootLevel: function(item) {

			var idProperty = item[this.idProperty],
				path = item[this.pathProperty],
				pathLength = path ? path.split(this.pathSeparator).length : null;

			if ((pathLength > this.pathLengthMinChildren || pathLength < this.pathLengthMinParent)) {
				return false;
			}

			return true;
			return !(pathLength > this.pathLengthMinChildren || pathLength < this.pathLengthMinParent);
		},

		_addItemWithoutInstance: function(idProperty, item) {
@@ -383,7 +361,7 @@ define([
			if (!rowParent) {
				this._addPendingParent(idProperty, idPropertyParent);
			} else {
				if (this._evaluateItem(item)) {
				if (this._checkItemBelongRootLevel(item)) {
					rowParent.pendingChildren = true;
				}

+3 −22
Original line number Diff line number Diff line
@@ -26,7 +26,7 @@ define([

			this._clearRowsData();

			this._proccesNewData(response);
			this._processNewData(response);

			this._clearOldRowsData();
		},
@@ -46,27 +46,6 @@ define([
			delete this._rowsOld;
		},

		_parserIndexData: function(response) {

			var data = response.data;

			if (data.data) {
				data = data.data;
			}

			return data;
		},

		_proccesNewData: function(response) {

			var data = this._parserIndexData(response);

			for (var i = 0; i < data.length; i++) {
				this._rescueOldInstance(data[i]);
				this._addItem(data[i]);
			}
		},

		_rescueOldInstance: function(item) {

			var idProperty = item[this.idProperty],
@@ -87,6 +66,8 @@ define([

		_addItem: function(item) {

			this._rescueOldInstance(item);

			var idProperty = item[this.idProperty],
				rowInstance = this._addOrUpdateRow(item),
				obj = {
+1 −1
Original line number Diff line number Diff line
@@ -185,7 +185,7 @@ define([
			var idProperty = item[this.idProperty],
				rowInstance = this._getRowInstance(idProperty);

			if (!rowInstance || !this._evaluateItem(item)) {
			if (!rowInstance || !this._checkItemBelongRootLevel(item)) {
				return;
			}

+4 −0
Original line number Diff line number Diff line
@@ -73,6 +73,10 @@ define([
			var row = this._getRow(idProperty),
				rowPending = this._rowsPending[idProperty] || {};

			if (!row) {
				return;
			}

			row.selected = rowPending.selected || {};
			row.mixed = rowPending.mixed || {};

Loading