Skip to content

Commit

Permalink
Optimize(Search): use LEFT JOIN filter on SELECT statement for Consum…
Browse files Browse the repository at this point in the history
…able (#17078)

* Optimize(Search): use LEFT JOIN filter on SELECT statement

* use 'computation' instead of 'workaround'

* clean use statement

* revert

* try to fix TU

* fix TU
  • Loading branch information
stonebuzz committed May 15, 2024
1 parent 5d34fae commit 70572e8
Showing 1 changed file with 17 additions and 8 deletions.
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

0 comments on commit 70572e8

Please sign in to comment.