Skip to content

Commit 8b6230d

Browse files
committed
Revert "Table: moved caching related functionality to separate classes (#185)"
This reverts commit a561254.
1 parent cf962df commit 8b6230d

File tree

6 files changed

+180
-415
lines changed

6 files changed

+180
-415
lines changed

src/Database/Table/ActiveRow.php

Lines changed: 8 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ public function __toString()
6868

6969
public function toArray(): array
7070
{
71-
$this->reloadAllColumns();
71+
$this->accessColumn(null);
7272
return $this->data;
7373
}
7474

@@ -204,7 +204,7 @@ public function delete(): int
204204

205205
public function getIterator(): \Iterator
206206
{
207-
$this->reloadAllColumns();
207+
$this->accessColumn(null);
208208
return new \ArrayIterator($this->data);
209209
}
210210

@@ -308,10 +308,14 @@ public function __unset($key)
308308
/**
309309
* @internal
310310
*/
311-
public function accessColumn(string $key, bool $selectColumn = true): bool
311+
public function accessColumn($key, bool $selectColumn = true): bool
312312
{
313313
if ($this->table->accessColumn($key, $selectColumn) && !$this->dataRefreshed) {
314-
$this->refreshData();
314+
if (!isset($this->table[$this->getSignature()])) {
315+
throw new Nette\InvalidStateException("Database refetch failed; row with signature '{$this->getSignature()}' does not exist!");
316+
}
317+
$this->data = $this->table[$this->getSignature()]->data;
318+
$this->dataRefreshed = true;
315319
}
316320
return isset($this->data[$key]) || array_key_exists($key, $this->data);
317321
}
@@ -321,22 +325,4 @@ protected function removeAccessColumn(string $key): void
321325
{
322326
$this->table->removeAccessColumn($key);
323327
}
324-
325-
326-
protected function reloadAllColumns(): void
327-
{
328-
if ($this->table->reloadAllColumns() && !$this->dataRefreshed) {
329-
$this->refreshData();
330-
}
331-
}
332-
333-
334-
protected function refreshData(): void
335-
{
336-
if (!isset($this->table[$this->getSignature()])) {
337-
throw new Nette\InvalidStateException("Database refetch failed; row with signature '{$this->getSignature()}' does not exist!");
338-
}
339-
$this->data = $this->table[$this->getSignature()]->data;
340-
$this->dataRefreshed = true;
341-
}
342328
}

src/Database/Table/ColumnAccessCache.php

Lines changed: 0 additions & 193 deletions
This file was deleted.

src/Database/Table/GroupedSelection.php

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,12 @@
2020
*/
2121
class GroupedSelection extends Selection
2222
{
23-
/** @var mixed current assigned referencing array */
24-
public $refCacheCurrent;
25-
2623
/** @var Selection referenced table */
2724
protected $refTable;
2825

26+
/** @var mixed current assigned referencing array */
27+
protected $refCacheCurrent;
28+
2929
/** @var string grouping column name */
3030
protected $column;
3131

@@ -92,8 +92,7 @@ public function order(string $columns, ...$params)
9292
*/
9393
public function aggregation(string $function)
9494
{
95-
$selectQueryHash = $this->sqlBuilder->getSelectQueryHash($this->cache->getPreviousAccessedColumns());
96-
$aggregation = &$this->getRefTable($refPath)->aggregation[$refPath . $function . $selectQueryHash];
95+
$aggregation = &$this->getRefTable($refPath)->aggregation[$refPath . $function . $this->sqlBuilder->getSelectQueryHash($this->getPreviousAccessedColumns())];
9796

9897
if ($aggregation === null) {
9998
$aggregation = [];
@@ -131,16 +130,16 @@ public function count(string $column = null): int
131130
protected function execute(): void
132131
{
133132
if ($this->rows !== null) {
134-
$this->cache->setObserveCache($this);
133+
$this->observeCache = $this;
135134
return;
136135
}
137136

138-
$accessedColumns = $this->cache->getAccessedColumns();
137+
$accessedColumns = $this->accessedColumns;
139138
$this->loadRefCache();
140139

141140
if (!isset($this->refCacheCurrent['data'])) {
142141
// we have not fetched any data yet => init accessedColumns by cached accessedColumns
143-
$this->cache->setAccessedColumns($accessedColumns);
142+
$this->accessedColumns = $accessedColumns;
144143

145144
$limit = $this->sqlBuilder->getLimit();
146145
$rows = count($this->refTable->rows);
@@ -168,7 +167,7 @@ protected function execute(): void
168167
$this->data = &$this->refCacheCurrent['data'][$this->active];
169168
}
170169

171-
$this->cache->setObserveCache($this);
170+
$this->observeCache = $this;
172171
if ($this->data === null) {
173172
$this->data = [];
174173
} else {
@@ -195,9 +194,12 @@ protected function getRefTable(&$refPath): Selection
195194

196195
protected function loadRefCache(): void
197196
{
198-
$referencing = &$this->refCache->getReferencing($this->cache->getGeneralCacheKey());
199-
$hash = $this->cache->loadFromRefCache($referencing);
197+
$hash = $this->getSpecificCacheKey();
198+
$referencing = &$this->refCache['referencing'][$this->getGeneralCacheKey()];
199+
$this->observeCache = &$referencing['observeCache'];
200200
$this->refCacheCurrent = &$referencing[$hash];
201+
$this->accessedColumns = &$referencing[$hash]['accessed'];
202+
$this->specificCacheKey = &$referencing[$hash]['specificCacheKey'];
201203
$this->rows = &$referencing[$hash]['rows'];
202204

203205
if (isset($referencing[$hash]['data'][$this->active])) {

src/Database/Table/ReferenceCache.php

Lines changed: 0 additions & 59 deletions
This file was deleted.

0 commit comments

Comments
 (0)