Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Optimize(Search): use LEFT JOIN filter on SELECT statement for Consumable #17078

Merged
merged 6 commits into from
May 15, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
25 changes: 17 additions & 8 deletions src/ConsumableItem.php
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,9 @@ public function defineTabs($options = [])

public function rawSearchOptions()
{
/** @var \DBmysql $DB */
global $DB;

$tab = parent::rawSearchOptions();

$tab[] = [
Expand Down Expand Up @@ -213,31 +216,37 @@ public function rawSearchOptions()
$tab[] = [
'id' => '17',
'table' => 'glpi_consumables',
'field' => 'id',
'field' => 'date_out',
'name' => __('Number of used consumables'),
'datatype' => 'count',
'datatype' => 'number',
'forcegroupby' => true,
'usehaving' => true,
'massiveaction' => false,
'nometa' => true,
'joinparams' => [
'jointype' => 'child',
'condition' => ['NOT' => ['NEWTABLE.date_out' => null]]
]
],
'computation' => new QueryExpression(
expression: QueryFunction::sum(new QueryExpression("CASE WHEN " . $DB::quoteName('TABLE.date_out') . " IS NULL THEN 1 ELSE 0 END"))
)
];

$tab[] = [
'id' => '19',
'table' => 'glpi_consumables',
'field' => 'id',
'field' => 'date_out',
'name' => __('Number of new consumables'),
'datatype' => 'count',
'datatype' => 'number',
'forcegroupby' => true,
'usehaving' => true,
'massiveaction' => false,
'nometa' => true,
'joinparams' => [
'jointype' => 'child',
'condition' => ['NEWTABLE.date_out' => null]
]
],
'computation' => new QueryExpression(
expression: QueryFunction::sum(new QueryExpression("CASE WHEN " . $DB::quoteName('TABLE.date_out') . " IS NOT NULL THEN 1 ELSE 0 END"))
)
];

$tab = array_merge($tab, Location::rawSearchOptionsToAdd());
Expand Down