Skip to content

Commit 95a8e37

Browse files
committed
Lazy search execution
Move search out of aggregation constructors. It should only be executed before actual rendering, not e.g. on metadata run
1 parent de7aa9a commit 95a8e37

9 files changed

+49
-26
lines changed

_test/mock/AggregationEditorTable.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ class AggregationEditorTable extends meta\AggregationEditorTable
88
{
99
public function getResult()
1010
{
11+
$this->executeSearch();
1112
return $this->result;
1213
}
1314
}

_test/mock/AggregationTable.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ class AggregationTable extends meta\AggregationTable
88
{
99
public function getResult()
1010
{
11+
$this->executeSearch();
1112
return $this->result;
1213
}
1314
}

action/aggregationeditor.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,7 @@ protected function saveRow()
144144
new SearchConfig($config)
145145
);
146146

147+
$editorTable->executeSearch();
147148
echo $editorTable->getFirstRow();
148149
}
149150

meta/Aggregation.php

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -60,10 +60,7 @@ public function __construct($id, $mode, \Doku_Renderer $renderer, SearchConfig $
6060
$this->mode = $mode;
6161
$this->renderer = $renderer;
6262
$this->searchConfig = $searchConfig;
63-
$this->data = $searchConfig->getConf();
64-
$this->columns = $searchConfig->getColumns();
65-
$this->result = $this->searchConfig->execute();
66-
$this->resultCount = $this->searchConfig->getCount();
63+
$this->data = $this->searchConfig->getConf();
6764
$this->helper = plugin_load('helper', 'struct_config');
6865
}
6966

@@ -104,6 +101,15 @@ public function getScopeClasses()
104101
return $classes;
105102
}
106103

104+
public function executeSearch()
105+
{
106+
$this->columns = $this->searchConfig->getColumns();
107+
$this->result = $this->searchConfig->execute();
108+
$this->resultCount = $this->searchConfig->getCount();
109+
110+
$this->postSearch();
111+
}
112+
107113
/**
108114
* Render the actual output to the renderer
109115
*
@@ -120,6 +126,9 @@ abstract public function render($showNotFound = false);
120126
*/
121127
public function startScope()
122128
{
129+
if ($this->mode !== 'metadata') {
130+
$this->executeSearch();
131+
}
123132
if ($this->mode == 'xhtml') {
124133
$classes = $this->getScopeClasses();
125134

@@ -130,6 +139,16 @@ public function startScope()
130139
}
131140
}
132141

142+
/**
143+
* Child classes can set their own class properties based on search result
144+
*
145+
* @return void
146+
*/
147+
public function postSearch()
148+
{
149+
return;
150+
}
151+
133152
/**
134153
* Closes anything opened in startScope()
135154
*

meta/AggregationCloud.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,8 @@ class AggregationCloud extends Aggregation
2020
* @see render() on the resulting object.
2121
*
2222
*/
23-
public function __construct($id, $mode, \Doku_Renderer $renderer, SearchCloud $searchConfig)
23+
public function postSearch()
2424
{
25-
parent::__construct($id, $mode, $renderer, $searchConfig);
26-
2725
$this->max = $this->result[0]['count'];
2826
$this->min = end($this->result)['count'];
2927
}

meta/AggregationEditorTable.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,7 @@ public function render($showNotFound = false)
2727
*/
2828
public function startScope()
2929
{
30-
// unique identifier for this aggregation
31-
$hash = md5(var_export($this->data, true));
32-
$this->renderer->info['struct_table_hash'] = $hash;
30+
parent::startScope();
3331

3432
if ($this->mode != 'xhtml') return;
3533

meta/AggregationList.php

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,17 @@ class AggregationList extends Aggregation
1212
/** @var int number of all results */
1313
protected $resultColumnCount;
1414

15-
/** @inheritdoc */
16-
public function __construct($id, $mode, \Doku_Renderer $renderer, SearchConfig $searchConfig)
15+
/**
16+
* Set our class property after search has been executed in parent
17+
* @return void
18+
*/
19+
public function startScope()
20+
{
21+
parent::startScope();
22+
}
23+
24+
public function postSearch()
1725
{
18-
parent::__construct($id, $mode, $renderer, $searchConfig);
1926
$this->resultColumnCount = count($this->columns);
2027
}
2128

meta/AggregationTable.php

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -19,18 +19,9 @@ class AggregationTable extends Aggregation
1919
protected $resultRids;
2020
protected $resultRevs;
2121

22-
public function __construct($id, $mode, \Doku_Renderer $renderer, SearchConfig $searchConfig)
23-
{
24-
parent::__construct($id, $mode, $renderer, $searchConfig);
25-
$this->resultPIDs = $this->searchConfig->getPids();
26-
$this->resultRids = $this->searchConfig->getRids();
27-
$this->resultRevs = $this->searchConfig->getRevs();
28-
}
29-
3022
/** @inheritdoc */
3123
public function render($showNotFound = false)
3224
{
33-
3425
// abort early if there are no results at all (not filtered)
3526
if (!$this->resultCount && !$this->isDynamicallyFiltered() && $showNotFound) {
3627
$this->renderer->cdata($this->helper->getLang('none'));
@@ -104,6 +95,13 @@ public function startScope()
10495
parent::startScope();
10596
}
10697

98+
public function postSearch()
99+
{
100+
$this->resultPIDs = $this->searchConfig->getPids();
101+
$this->resultRids = $this->searchConfig->getRids();
102+
$this->resultRevs = $this->searchConfig->getRevs();
103+
}
104+
107105
/**
108106
* Closes the table and anything opened in startScope()
109107
*

syntax/table.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -122,13 +122,13 @@ public function render($format, Doku_Renderer $renderer, $config)
122122
throw new StructException('Aggregation class does not inherit Aggregation: ' . $this->tableclass);
123123
}
124124

125-
$table->startScope();
126-
$table->render(true);
127-
$table->finishScope();
128-
129125
if ($format === 'metadata') {
130126
/** @var Doku_Renderer_metadata $renderer */
131127
$renderer->meta['plugin']['struct']['hasaggregation'] = $search->getCacheFlag();
128+
} else {
129+
$table->startScope();
130+
$table->render(true);
131+
$table->finishScope();
132132
}
133133
} catch (StructException $e) {
134134
msg($e->getMessage(), -1, $e->getLine(), $e->getFile());

0 commit comments

Comments
 (0)