Skip to content

Commit

Permalink
Revert "Lazy search execution"
Browse files Browse the repository at this point in the history
This reverts commit 95a8e37.
  • Loading branch information
annda committed Jan 18, 2024
1 parent 95a8e37 commit 67f70d5
Show file tree
Hide file tree
Showing 9 changed files with 26 additions and 49 deletions.
1 change: 0 additions & 1 deletion _test/mock/AggregationEditorTable.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ class AggregationEditorTable extends meta\AggregationEditorTable
{
public function getResult()
{
$this->executeSearch();
return $this->result;
}
}
1 change: 0 additions & 1 deletion _test/mock/AggregationTable.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ class AggregationTable extends meta\AggregationTable
{
public function getResult()
{
$this->executeSearch();
return $this->result;
}
}
1 change: 0 additions & 1 deletion action/aggregationeditor.php
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,6 @@ protected function saveRow()
new SearchConfig($config)
);

$editorTable->executeSearch();
echo $editorTable->getFirstRow();
}

Expand Down
27 changes: 4 additions & 23 deletions meta/Aggregation.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,10 @@ public function __construct($id, $mode, \Doku_Renderer $renderer, SearchConfig $
$this->mode = $mode;
$this->renderer = $renderer;
$this->searchConfig = $searchConfig;
$this->data = $this->searchConfig->getConf();
$this->data = $searchConfig->getConf();
$this->columns = $searchConfig->getColumns();
$this->result = $this->searchConfig->execute();
$this->resultCount = $this->searchConfig->getCount();
$this->helper = plugin_load('helper', 'struct_config');
}

Expand Down Expand Up @@ -101,15 +104,6 @@ public function getScopeClasses()
return $classes;
}

public function executeSearch()
{
$this->columns = $this->searchConfig->getColumns();
$this->result = $this->searchConfig->execute();
$this->resultCount = $this->searchConfig->getCount();

$this->postSearch();
}

/**
* Render the actual output to the renderer
*
Expand All @@ -126,9 +120,6 @@ abstract public function render($showNotFound = false);
*/
public function startScope()
{
if ($this->mode !== 'metadata') {
$this->executeSearch();
}
if ($this->mode == 'xhtml') {
$classes = $this->getScopeClasses();

Expand All @@ -139,16 +130,6 @@ public function startScope()
}
}

/**
* Child classes can set their own class properties based on search result
*
* @return void
*/
public function postSearch()
{
return;
}

/**
* Closes anything opened in startScope()
*
Expand Down
4 changes: 3 additions & 1 deletion meta/AggregationCloud.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,10 @@ class AggregationCloud extends Aggregation
* @see render() on the resulting object.
*
*/
public function postSearch()
public function __construct($id, $mode, \Doku_Renderer $renderer, SearchCloud $searchConfig)
{
parent::__construct($id, $mode, $renderer, $searchConfig);

$this->max = $this->result[0]['count'];
$this->min = end($this->result)['count'];
}
Expand Down
4 changes: 3 additions & 1 deletion meta/AggregationEditorTable.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,9 @@ public function render($showNotFound = false)
*/
public function startScope()
{
parent::startScope();
// unique identifier for this aggregation
$hash = md5(var_export($this->data, true));
$this->renderer->info['struct_table_hash'] = $hash;

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

Expand Down
13 changes: 3 additions & 10 deletions meta/AggregationList.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,10 @@ class AggregationList extends Aggregation
/** @var int number of all results */
protected $resultColumnCount;

/**
* Set our class property after search has been executed in parent
* @return void
*/
public function startScope()
{
parent::startScope();
}

public function postSearch()
/** @inheritdoc */
public function __construct($id, $mode, \Doku_Renderer $renderer, SearchConfig $searchConfig)
{
parent::__construct($id, $mode, $renderer, $searchConfig);
$this->resultColumnCount = count($this->columns);
}

Expand Down
16 changes: 9 additions & 7 deletions meta/AggregationTable.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,18 @@ class AggregationTable extends Aggregation
protected $resultRids;
protected $resultRevs;

public function __construct($id, $mode, \Doku_Renderer $renderer, SearchConfig $searchConfig)
{
parent::__construct($id, $mode, $renderer, $searchConfig);
$this->resultPIDs = $this->searchConfig->getPids();
$this->resultRids = $this->searchConfig->getRids();
$this->resultRevs = $this->searchConfig->getRevs();
}

/** @inheritdoc */
public function render($showNotFound = false)
{

// abort early if there are no results at all (not filtered)
if (!$this->resultCount && !$this->isDynamicallyFiltered() && $showNotFound) {
$this->renderer->cdata($this->helper->getLang('none'));
Expand Down Expand Up @@ -95,13 +104,6 @@ public function startScope()
parent::startScope();
}

public function postSearch()
{
$this->resultPIDs = $this->searchConfig->getPids();
$this->resultRids = $this->searchConfig->getRids();
$this->resultRevs = $this->searchConfig->getRevs();
}

/**
* Closes the table and anything opened in startScope()
*
Expand Down
8 changes: 4 additions & 4 deletions syntax/table.php
Original file line number Diff line number Diff line change
Expand Up @@ -122,13 +122,13 @@ public function render($format, Doku_Renderer $renderer, $config)
throw new StructException('Aggregation class does not inherit Aggregation: ' . $this->tableclass);
}

$table->startScope();
$table->render(true);
$table->finishScope();

if ($format === 'metadata') {
/** @var Doku_Renderer_metadata $renderer */
$renderer->meta['plugin']['struct']['hasaggregation'] = $search->getCacheFlag();
} else {
$table->startScope();
$table->render(true);
$table->finishScope();
}
} catch (StructException $e) {
msg($e->getMessage(), -1, $e->getLine(), $e->getFile());
Expand Down

0 comments on commit 67f70d5

Please sign in to comment.