Reorder return values of VariableBase::getValue() so that the value can be quickly accessed

This commit is contained in:
Kijin Sung 2025-02-15 22:25:25 +09:00
parent 0d14aca1c0
commit fd0491cb0d
3 changed files with 18 additions and 15 deletions

View file

@ -487,9 +487,9 @@ class DB
}
// Collect various counts used in the page calculation.
list($is_expression, $list_count) = $query->navigation->list_count->getValue($args);
list($is_expression, $page_count) = $query->navigation->page_count->getValue($args);
list($is_expression, $page) = $query->navigation->page->getValue($args);
$list_count = $query->navigation->list_count->getValue($args)[0];
$page_count = $query->navigation->page_count->getValue($args)[0];
$page = $query->navigation->page->getValue($args)[0];
$total_count = intval($count);
$total_page = max(1, intval(ceil($total_count / $list_count)));
$last_index = $total_count - (($page - 1) * $list_count);

View file

@ -609,7 +609,7 @@ class Query extends VariableBase
{
// Get the name of the column or expression to order by.
$column_name = '';
list($is_expression, $column_name) = $orderby->getValue($this->_args);
list($column_name, $is_expression) = $orderby->getValue($this->_args);
if (!$column_name)
{
continue;
@ -649,7 +649,7 @@ class Query extends VariableBase
protected function _arrangeLimitOffset(Navigation $navigation): string
{
// Get the list count.
list($is_expression, $list_count) = $navigation->list_count->getValue($this->_args);
$list_count = $navigation->list_count->getValue($this->_args)[0];
if ($list_count <= 0)
{
return '';
@ -660,11 +660,11 @@ class Query extends VariableBase
// Get the offset from the page or offset variable.
if ($navigation->page)
{
list($is_expression, $page) = $navigation->page->getValue($this->_args);
$page = $navigation->page->getValue($this->_args)[0];
}
if ($navigation->offset)
{
list($is_expression, $offset) = $navigation->offset->getValue($this->_args);
$offset = $navigation->offset->getValue($this->_args)[0];
}
// If page is available, set the offset and require pagination for this query.

View file

@ -281,11 +281,17 @@ class VariableBase
/**
* Get the current value, falling back to the default value if necessary.
*
* Format of return value: [value, is_expression, is_default_value]
*
* @param array $args
* @return array
*/
public function getValue(array $args): array
{
$value = null;
$is_expression = false;
$is_default_value = false;
if ($this->var && Query::isValidVariable($args[$this->var] ?? null, $this instanceof ColumnWrite))
{
if ($args[$this->var] === '')
@ -293,35 +299,32 @@ class VariableBase
if ($this instanceof ColumnWrite)
{
$value = $args[$this->var];
$is_expression = false;
}
else
{
list($is_expression, $value) = $this->getDefaultValue();
$is_default_value = true;
}
}
else
{
$is_expression = false;
$value = $args[$this->var];
}
}
elseif ($this->default !== null)
{
list($is_expression, $value) = $this->getDefaultValue();
}
else
{
$is_expression = null;
$value = null;
$is_default_value = true;
}
return [$is_expression, $value];
return [$value, $is_expression, $is_default_value];
}
/**
* Get the default value of this variable.
*
* Format of return value: [is_expression, value]
*
* @return array
*/
public function getDefaultValue(): array