Skip to content
Extraits de code Groupes Projets
Valider 46603d8e rédigé par Thomas Steur's avatar Thomas Steur
Parcourir les fichiers

further dataTable performance improvements

parent aead5ce7
Aucune branche associée trouvée
Aucune étiquette associée trouvée
Aucune requête de fusion associée trouvée
...@@ -591,9 +591,6 @@ class DataTable implements DataTableInterface, \IteratorAggregate, \ArrayAccess ...@@ -591,9 +591,6 @@ class DataTable implements DataTableInterface, \IteratorAggregate, \ArrayAccess
public function getRowFromLabel($label) public function getRowFromLabel($label)
{ {
$rowId = $this->getRowIdFromLabel($label); $rowId = $this->getRowIdFromLabel($label);
if ($rowId instanceof Row) {
return $rowId;
}
if (is_int($rowId) && isset($this->rows[$rowId])) { if (is_int($rowId) && isset($this->rows[$rowId])) {
return $this->rows[$rowId]; return $this->rows[$rowId];
} }
...@@ -602,6 +599,9 @@ class DataTable implements DataTableInterface, \IteratorAggregate, \ArrayAccess ...@@ -602,6 +599,9 @@ class DataTable implements DataTableInterface, \IteratorAggregate, \ArrayAccess
) { ) {
return $this->summaryRow; return $this->summaryRow;
} }
if ($rowId instanceof Row) {
return $rowId;
}
return false; return false;
} }
...@@ -626,7 +626,8 @@ class DataTable implements DataTableInterface, \IteratorAggregate, \ArrayAccess ...@@ -626,7 +626,8 @@ class DataTable implements DataTableInterface, \IteratorAggregate, \ArrayAccess
return self::ID_SUMMARY_ROW; return self::ID_SUMMARY_ROW;
} }
$label = (string)$label; $label = (string) $label;
if (!isset($this->rowsIndexByLabel[$label])) { if (!isset($this->rowsIndexByLabel[$label])) {
return false; return false;
} }
...@@ -657,12 +658,19 @@ class DataTable implements DataTableInterface, \IteratorAggregate, \ArrayAccess ...@@ -657,12 +658,19 @@ class DataTable implements DataTableInterface, \IteratorAggregate, \ArrayAccess
{ {
$this->rebuildIndexContinuously = true; $this->rebuildIndexContinuously = true;
foreach ($this->getRows() as $id => $row) { foreach ($this->rows as $id => $row) {
$label = $row->getColumn('label'); $label = $row->getColumn('label');
if ($label !== false) { if ($label !== false) {
$this->rowsIndexByLabel[$label] = $id; $this->rowsIndexByLabel[$label] = $id;
} }
} }
if ($this->summaryRow) {
$label = $this->summaryRow->getColumn('label');
if ($label !== false) {
$this->rowsIndexByLabel[$label] = DataTable::ID_SUMMARY_ROW;
}
}
$this->indexNotUpToDate = false; $this->indexNotUpToDate = false;
} }
......
...@@ -95,15 +95,12 @@ class Sort extends BaseFilter ...@@ -95,15 +95,12 @@ class Sort extends BaseFilter
/** /**
* Sorting method used for sorting values natural * Sorting method used for sorting values natural
* *
* @param array $rowA array[0 => value of column to sort, 1 => label] * @param mixed $valA
* @param array $rowB array[0 => value of column to sort, 1 => label] * @param mixed $valB
* @return int * @return int
*/ */
function naturalSort($rowA, $rowB) function naturalSort($valA, $valB)
{ {
$valA = $rowA[0];
$valB = $rowB[0];
return !isset($valA) return !isset($valA)
&& !isset($valB) && !isset($valB)
? 0 ? 0
...@@ -122,15 +119,12 @@ class Sort extends BaseFilter ...@@ -122,15 +119,12 @@ class Sort extends BaseFilter
/** /**
* Sorting method used for sorting values * Sorting method used for sorting values
* *
* @param array $rowA array[0 => value of column to sort, 1 => label] * @param mixed $valA
* @param array $rowB array[0 => value of column to sort, 1 => label] * @param mixed $valB
* @return int * @return int
*/ */
function sortString($rowA, $rowB) function sortString($valA, $valB)
{ {
$valA = $rowA[0];
$valB = $rowB[0];
return !isset($valA) return !isset($valA)
&& !isset($valB) && !isset($valB)
? 0 ? 0
...@@ -150,11 +144,10 @@ class Sort extends BaseFilter ...@@ -150,11 +144,10 @@ class Sort extends BaseFilter
{ {
$value = $row->getColumn($this->columnToSort); $value = $row->getColumn($this->columnToSort);
if ($value === false if ($value === false || is_array($value)) {
|| is_array($value)
) {
return null; return null;
} }
return $value; return $value;
} }
...@@ -239,7 +232,7 @@ class Sort extends BaseFilter ...@@ -239,7 +232,7 @@ class Sort extends BaseFilter
private function getFirstValueFromDataTable($table) private function getFirstValueFromDataTable($table)
{ {
foreach ($table->getRows() as $row) { foreach ($table->getRowsWithoutSummaryRow() as $row) {
$value = $this->getColumnValue($row); $value = $this->getColumnValue($row);
if (!is_null($value)) { if (!is_null($value)) {
return $value; return $value;
...@@ -262,8 +255,14 @@ class Sort extends BaseFilter ...@@ -262,8 +255,14 @@ class Sort extends BaseFilter
// get column value and label only once for performance tweak // get column value and label only once for performance tweak
$values = array(); $values = array();
foreach ($rows as $key => $row) { if ($functionCallback === 'numberSort') {
$values[$key] = array($this->getColumnValue($row), $row->getColumn('label')); foreach ($rows as $key => $row) {
$values[$key] = array($this->getColumnValue($row), $row->getColumn('label'));
}
} else {
foreach ($rows as $key => $row) {
$values[$key] = $this->getColumnValue($row);
}
} }
uasort($values, array($this, $functionCallback)); uasort($values, array($this, $functionCallback));
......
0% Chargement en cours ou .
You are about to add 0 people to the discussion. Proceed with caution.
Terminez d'abord l'édition de ce message.
Veuillez vous inscrire ou vous pour commenter