Skip to content

Commit 79e62cc

Browse files
committed
ActiveRow: optimization
1 parent be69d1d commit 79e62cc

File tree

2 files changed

+8
-9
lines changed

2 files changed

+8
-9
lines changed

src/Database/Table/ActiveRow.php

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -281,8 +281,7 @@ public function __set($key, $value)
281281
*/
282282
public function &__get($key)
283283
{
284-
$this->accessColumn($key);
285-
if (array_key_exists($key, $this->data)) {
284+
if ($this->accessColumn($key)) {
286285
return $this->data[$key];
287286
}
288287

@@ -300,8 +299,7 @@ public function &__get($key)
300299

301300
public function __isset($key)
302301
{
303-
$this->accessColumn($key);
304-
if (array_key_exists($key, $this->data)) {
302+
if ($this->accessColumn($key)) {
305303
return isset($this->data[$key]);
306304
}
307305
$this->removeAccessColumn($key);
@@ -320,15 +318,14 @@ public function __unset($key)
320318
*/
321319
public function accessColumn($key, $selectColumn = TRUE)
322320
{
323-
$this->table->accessColumn($key, $selectColumn);
324-
if ($this->table->getDataRefreshed() && !$this->dataRefreshed) {
321+
if ($this->table->accessColumn($key, $selectColumn) && !$this->dataRefreshed) {
325322
if (!isset($this->table[$this->getSignature()])) {
326323
throw new Nette\InvalidStateException('Database refetch failed; row does not exist!');
327324
}
328325
$this->data = $this->table[$this->getSignature()]->data;
329326
$this->dataRefreshed = TRUE;
330327
}
331-
return array_key_exists($key, $this->data);
328+
return isset($this->data[$key]) || array_key_exists($key, $this->data);
332329
}
333330

334331

src/Database/Table/Selection.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -644,11 +644,12 @@ protected function getSpecificCacheKey()
644644
* @internal
645645
* @param string|NULL column name or NULL to reload all columns
646646
* @param bool
647+
* @return bool if selection requeried for more columns.
647648
*/
648649
public function accessColumn($key, $selectColumn = TRUE)
649650
{
650651
if (!$this->cache) {
651-
return;
652+
return FALSE;
652653
}
653654

654655
if ($key === NULL) {
@@ -658,7 +659,7 @@ public function accessColumn($key, $selectColumn = TRUE)
658659
$this->accessedColumns[$key] = $selectColumn;
659660
}
660661

661-
if ($selectColumn && !$this->sqlBuilder->getSelect() && $this->previousAccessedColumns && ($key === NULL || !isset($this->previousAccessedColumns[$key]))) {
662+
if ($selectColumn && $this->previousAccessedColumns && ($key === NULL || !isset($this->previousAccessedColumns[$key])) && !$this->sqlBuilder->getSelect()) {
662663
$this->previousAccessedColumns = [];
663664

664665
if ($this->sqlBuilder->getLimit()) {
@@ -693,6 +694,7 @@ public function accessColumn($key, $selectColumn = TRUE)
693694
}
694695
}
695696
}
697+
return $this->dataRefreshed;
696698
}
697699

698700

0 commit comments

Comments
 (0)