Skip to content
Merged
Show file tree
Hide file tree
Changes from 15 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
<?php

/**
* ---------------------------------------------------------------------
*
* GLPI - Gestionnaire Libre de Parc Informatique
*
* http://glpi-project.org
*
* @copyright 2015-2025 Teclib' and contributors.
* @licence https://www.gnu.org/licenses/gpl-3.0.html
*
* ---------------------------------------------------------------------
*
* LICENSE
*
* This file is part of GLPI.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*
* ---------------------------------------------------------------------
*/
/**
* @var Migration $migration
*/

$assets_tables_with_templates_and_trashbin = [
'glpi_budgets',
'glpi_certificates',
'glpi_computers',
'glpi_contracts',
'glpi_domains',
'glpi_cables',
'glpi_monitors',
'glpi_networkequipments',
'glpi_passivedcequipments',
'glpi_peripherals',
'glpi_phones',
'glpi_printers',
'glpi_projects',
'glpi_projecttasks',
'glpi_softwarelicenses',
'glpi_softwares',
'glpi_racks',
'glpi_enclosures',
'glpi_pdus',
'glpi_assets_assets',
];

foreach ($assets_tables_with_templates_and_trashbin as $table) {
$migration->addKey($table, ['is_deleted', 'is_template'], 'active_assets');
$migration->dropKey($table, 'is_deleted');
}
44 changes: 22 additions & 22 deletions install/mysql/glpi-empty.sql
Original file line number Diff line number Diff line change
Expand Up @@ -316,10 +316,10 @@ CREATE TABLE `glpi_budgets` (
KEY `name` (`name`),
KEY `is_recursive` (`is_recursive`),
KEY `entities_id` (`entities_id`),
KEY `is_deleted` (`is_deleted`),
KEY `begin_date` (`begin_date`),
KEY `end_date` (`end_date`),
KEY `is_template` (`is_template`),
KEY `active_assets` (`is_deleted`, `is_template`),
KEY `date_mod` (`date_mod`),
KEY `date_creation` (`date_creation`),
KEY `locations_id` (`locations_id`),
Expand Down Expand Up @@ -560,7 +560,7 @@ CREATE TABLE `glpi_certificates` (
KEY `entities_id` (`entities_id`),
KEY `is_recursive` (`is_recursive`),
KEY `is_template` (`is_template`),
KEY `is_deleted` (`is_deleted`),
KEY `active_assets` (`is_deleted`, `is_template`),
KEY `certificatetypes_id` (`certificatetypes_id`),
KEY `users_id_tech` (`users_id_tech`),
KEY `users_id` (`users_id`),
Expand Down Expand Up @@ -1009,7 +1009,7 @@ CREATE TABLE `glpi_computers` (
KEY `states_id` (`states_id`),
KEY `users_id_tech` (`users_id_tech`),
KEY `computertypes_id` (`computertypes_id`),
KEY `is_deleted` (`is_deleted`),
KEY `active_assets` (`is_deleted`, `is_template`),
KEY `is_dynamic` (`is_dynamic`),
KEY `serial` (`serial`),
KEY `otherserial` (`otherserial`),
Expand Down Expand Up @@ -1519,8 +1519,8 @@ CREATE TABLE `glpi_contracts` (
KEY `locations_id` (`locations_id`),
KEY `entities_id` (`entities_id`),
KEY `is_recursive` (`is_recursive`),
KEY `is_deleted` (`is_deleted`),
KEY `is_template` (`is_template`),
KEY `active_assets` (`is_deleted`, `is_template`),
KEY `use_sunday` (`use_sunday`),
KEY `use_saturday` (`use_saturday`),
KEY `alert` (`alert`),
Expand Down Expand Up @@ -2694,8 +2694,8 @@ CREATE TABLE `glpi_domains` (
KEY `users_id` (`users_id`),
KEY `users_id_tech` (`users_id_tech`),
KEY `date_mod` (`date_mod`),
KEY `is_deleted` (`is_deleted`),
KEY `is_template` (`is_template`),
KEY `active_assets` (`is_deleted`, `is_template`),
KEY `is_active` (`is_active`),
KEY `date_expiration` (`date_expiration`),
KEY `date_domaincreation` (`date_domaincreation`),
Expand Down Expand Up @@ -4443,7 +4443,7 @@ CREATE TABLE `glpi_monitors` (
KEY `states_id` (`states_id`),
KEY `users_id_tech` (`users_id_tech`),
KEY `monitortypes_id` (`monitortypes_id`),
KEY `is_deleted` (`is_deleted`),
KEY `active_assets` (`is_deleted`, `is_template`),
KEY `is_dynamic` (`is_dynamic`),
KEY `autoupdatesystems_id` (`autoupdatesystems_id`),
KEY `serial` (`serial`),
Expand Down Expand Up @@ -4548,7 +4548,7 @@ CREATE TABLE `glpi_cables` (
KEY `cabletypes_id` (`cabletypes_id`),
KEY `date_mod` (`date_mod`),
KEY `date_creation` (`date_creation`),
KEY `is_deleted` (`is_deleted`)
KEY `active_assets` (`is_deleted`, `is_template`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci ROW_FORMAT=DYNAMIC;


Expand Down Expand Up @@ -4693,7 +4693,7 @@ CREATE TABLE `glpi_networkequipments` (
KEY `states_id` (`states_id`),
KEY `users_id_tech` (`users_id_tech`),
KEY `networkequipmenttypes_id` (`networkequipmenttypes_id`),
KEY `is_deleted` (`is_deleted`),
KEY `active_assets` (`is_deleted`, `is_template`),
KEY `date_mod` (`date_mod`),
KEY `is_dynamic` (`is_dynamic`),
KEY `serial` (`serial`),
Expand Down Expand Up @@ -5247,7 +5247,7 @@ CREATE TABLE `glpi_passivedcequipments` (
KEY `users_id` (`users_id`),
KEY `users_id_tech` (`users_id_tech`),
KEY `is_template` (`is_template`),
KEY `is_deleted` (`is_deleted`),
KEY `active_assets` (`is_deleted`, `is_template`),
KEY `states_id` (`states_id`),
KEY `manufacturers_id` (`manufacturers_id`),
KEY `date_creation` (`date_creation`),
Expand Down Expand Up @@ -5368,7 +5368,7 @@ CREATE TABLE `glpi_peripherals` (
KEY `states_id` (`states_id`),
KEY `users_id_tech` (`users_id_tech`),
KEY `peripheraltypes_id` (`peripheraltypes_id`),
KEY `is_deleted` (`is_deleted`),
KEY `active_assets` (`is_deleted`, `is_template`),
KEY `date_mod` (`date_mod`),
KEY `is_dynamic` (`is_dynamic`),
KEY `autoupdatesystems_id` (`autoupdatesystems_id`),
Expand Down Expand Up @@ -5482,7 +5482,7 @@ CREATE TABLE `glpi_phones` (
KEY `states_id` (`states_id`),
KEY `users_id_tech` (`users_id_tech`),
KEY `phonetypes_id` (`phonetypes_id`),
KEY `is_deleted` (`is_deleted`),
KEY `active_assets` (`is_deleted`, `is_template`),
KEY `date_mod` (`date_mod`),
KEY `is_dynamic` (`is_dynamic`),
KEY `autoupdatesystems_id` (`autoupdatesystems_id`),
Expand Down Expand Up @@ -5624,7 +5624,7 @@ CREATE TABLE `glpi_printers` (
KEY `states_id` (`states_id`),
KEY `users_id_tech` (`users_id_tech`),
KEY `printertypes_id` (`printertypes_id`),
KEY `is_deleted` (`is_deleted`),
KEY `active_assets` (`is_deleted`, `is_template`),
KEY `date_mod` (`date_mod`),
KEY `last_pages_counter` (`last_pages_counter`),
KEY `is_dynamic` (`is_dynamic`),
Expand Down Expand Up @@ -5990,7 +5990,6 @@ CREATE TABLE `glpi_projects` (
KEY `code` (`code`),
KEY `entities_id` (`entities_id`),
KEY `is_recursive` (`is_recursive`),
KEY `is_deleted` (`is_deleted`),
KEY `projects_id` (`projects_id`),
KEY `projectstates_id` (`projectstates_id`),
KEY `projecttypes_id` (`projecttypes_id`),
Expand All @@ -6007,7 +6006,8 @@ CREATE TABLE `glpi_projects` (
KEY `show_on_global_gantt` (`show_on_global_gantt`),
KEY `date_creation` (`date_creation`),
KEY `projecttemplates_id` (`projecttemplates_id`),
KEY `is_template` (`is_template`)
KEY `is_template` (`is_template`),
KEY `active_assets` (`is_deleted`, `is_template`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci ROW_FORMAT=DYNAMIC;


Expand Down Expand Up @@ -6069,7 +6069,6 @@ CREATE TABLE `glpi_projecttasks` (
KEY `is_recursive` (`is_recursive`),
KEY `projects_id` (`projects_id`),
KEY `projecttasks_id` (`projecttasks_id`),
KEY `is_deleted` (`is_deleted`),
KEY `date_creation` (`date_creation`),
KEY `date_mod` (`date_mod`),
KEY `users_id` (`users_id`),
Expand All @@ -6082,6 +6081,7 @@ CREATE TABLE `glpi_projecttasks` (
KEY `projecttasktypes_id` (`projecttasktypes_id`),
KEY `projecttasktemplates_id` (`projecttasktemplates_id`),
KEY `is_template` (`is_template`),
KEY `active_assets` (`is_deleted`, `is_template`),
KEY `is_milestone` (`is_milestone`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci ROW_FORMAT=DYNAMIC;

Expand Down Expand Up @@ -6811,7 +6811,7 @@ CREATE TABLE `glpi_softwarelicenses` (
KEY `users_id_tech` (`users_id_tech`),
KEY `users_id` (`users_id`),
KEY `is_helpdesk_visible` (`is_helpdesk_visible`),
KEY `is_deleted` (`is_deleted`),
KEY `active_assets` (`is_deleted`, `is_template`),
KEY `date_creation` (`date_creation`),
KEY `manufacturers_id` (`manufacturers_id`),
KEY `states_id` (`states_id`),
Expand Down Expand Up @@ -6886,9 +6886,9 @@ CREATE TABLE `glpi_softwares` (
KEY `locations_id` (`locations_id`),
KEY `users_id_tech` (`users_id_tech`),
KEY `softwares_id` (`softwares_id`),
KEY `is_deleted` (`is_deleted`),
KEY `is_helpdesk_visible` (`is_helpdesk_visible`),
KEY `date_creation` (`date_creation`)
KEY `date_creation` (`date_creation`),
KEY `active_assets` (`is_deleted`,`is_template`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci ROW_FORMAT=DYNAMIC;


Expand Down Expand Up @@ -8388,7 +8388,7 @@ CREATE TABLE `glpi_racks` (
KEY `users_id` (`users_id`),
KEY `users_id_tech` (`users_id_tech`),
KEY `is_template` (`is_template`),
KEY `is_deleted` (`is_deleted`),
KEY `active_assets` (`is_deleted`, `is_template`),
KEY `dcrooms_id` (`dcrooms_id`),
KEY `date_creation` (`date_creation`),
KEY `date_mod` (`date_mod`)
Expand Down Expand Up @@ -8465,7 +8465,7 @@ CREATE TABLE `glpi_enclosures` (
KEY `users_id` (`users_id`),
KEY `users_id_tech` (`users_id_tech`),
KEY `is_template` (`is_template`),
KEY `is_deleted` (`is_deleted`),
KEY `active_assets` (`is_deleted`, `is_template`),
KEY `states_id` (`states_id`),
KEY `manufacturers_id` (`manufacturers_id`),
KEY `date_mod` (`date_mod`),
Expand Down Expand Up @@ -8558,7 +8558,7 @@ CREATE TABLE `glpi_pdus` (
KEY `users_id` (`users_id`),
KEY `users_id_tech` (`users_id_tech`),
KEY `is_template` (`is_template`),
KEY `is_deleted` (`is_deleted`),
KEY `active_assets` (`is_deleted`, `is_template`),
KEY `states_id` (`states_id`),
KEY `manufacturers_id` (`manufacturers_id`),
KEY `pdutypes_id` (`pdutypes_id`),
Expand Down Expand Up @@ -10044,7 +10044,7 @@ CREATE TABLE `glpi_assets_assets` (
KEY `states_id` (`states_id`),
KEY `entities_id` (`entities_id`),
KEY `is_recursive` (`is_recursive`),
KEY `is_deleted` (`is_deleted`),
KEY `active_assets` (`is_deleted`, `is_template`),
KEY `is_template` (`is_template`),
KEY `is_dynamic` (`is_dynamic`),
KEY `autoupdatesystems_id` (`autoupdatesystems_id`),
Expand Down
12 changes: 12 additions & 0 deletions src/Glpi/Dashboard/Filter.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,13 @@ class Filter extends CommonDBChild
*/
public static function getAppliableFilters(string $table): array
{
global $GLPI_CACHE;

$cache_key = "dashboard_filters_appliable_$table" . Session::getLoginUserID();
if (($filters_ids = $GLPI_CACHE->get($cache_key)) !== null) {
return $filters_ids;
}

$filters_ids = [];

foreach (self::getRegisteredFilterClasses() as $filter_class) {
Expand All @@ -77,6 +84,11 @@ public static function getAppliableFilters(string $table): array
}
}

// Set a short cache to have an auto-invalidation;
// 5s should be enough to load a full dashboard
// and expiring before the user hit another request.
$GLPI_CACHE->set($cache_key, $filters_ids, 5);

return $filters_ids;
}

Expand Down
9 changes: 6 additions & 3 deletions src/Glpi/Dashboard/Grid.php
Original file line number Diff line number Diff line change
Expand Up @@ -960,6 +960,8 @@ public function getCardHtml(string $card_id = "", array $card_options = []): str
{
global $GLPI_CACHE;

$start = microtime(true);

$force = ($card_options['args']['force'] ?? $card_options['force'] ?? false);

// retrieve card
Expand Down Expand Up @@ -1068,9 +1070,10 @@ public function getCardHtml(string $card_id = "", array $card_options = []): str
Profiler::getInstance()->stop(__METHOD__ . ' get card data');

if ($_SESSION['glpi_use_mode'] === Session::DEBUG_MODE) {
// Use the current PHP request duration as the execution time for a more accurate card loading time
$execution_time = Profiler::getInstance()->getCurrentDuration('php_request');
$html .= '<span class="debug-card">' . \htmlescape($execution_time) . 'ms</span>';
$html .= '<span class="debug-card">';
$html .= "query: " . \htmlescape(Profiler::getInstance()->getCurrentDuration('php_request')) . 'ms - ';
$html .= "card: " . \htmlescape(round((microtime(true) - $start) * 1000)) . 'ms';
$html .= '</span>';
}

return $html;
Expand Down
27 changes: 23 additions & 4 deletions src/Glpi/Dashboard/Provider.php
Original file line number Diff line number Diff line change
Expand Up @@ -130,9 +130,11 @@ public static function bigNumberItem(?CommonDBTM $item = null, array $params = [
$where += getEntitiesRestrictCriteria($item::getTable(), '', '', $item->maybeRecursive());
}
$request = [
'SELECT' => ['COUNT DISTINCT' => $item::getTableField($item::getIndexName()) . ' as cpt'],
'FROM' => $i_table,
'WHERE' => $where,
'SELECT' => $item::getTableField($item::getIndexName()),
'COUNT' => 'cpt',
'DISTINCT' => true,
'FROM' => $i_table,
'WHERE' => $where,
];
}

Expand All @@ -141,6 +143,15 @@ public static function bigNumberItem(?CommonDBTM $item = null, array $params = [
self::getFiltersCriteria($i_table, $params['apply_filters']),
$item instanceof Ticket ? Ticket::getCriteriaFromProfile() : []
);

// avoid costy DISTINCT if there isn't any JOIN (/3 perf gain)
if (!isset($request['LEFT JOIN'])
&& !isset($request['JOIN'])
&& !isset($request['INNER JOIN'])
&& !isset($request['RIGHT JOIN'])) {
unset($request['DISTINCT']);
}

Profiler::getInstance()->stop(__METHOD__ . ' build SQL criteria');
$iterator = $DB->request($criteria);

Expand Down Expand Up @@ -868,7 +879,7 @@ public static function nbItemByFk(
],
],
],
'GROUPBY' => "$fk_table.$name",
'GROUPBY' => "$fk_table.id",
'ORDERBY' => "cpt DESC",
'LIMIT' => $params['limit'],
],
Expand Down Expand Up @@ -1280,6 +1291,14 @@ public static function getTicketsStatus(array $params = []): array
self::getFiltersCriteria($t_table, $params['apply_filters'])
);

// avoid costy DISTINCT if there isn't any JOIN (/3 perf gain)
if (!isset($sub_query['LEFT JOIN'])
&& !isset($sub_query['JOIN'])
&& !isset($sub_query['INNER JOIN'])
&& !isset($sub_query['RIGHT JOIN'])) {
unset($sub_query['DISTINCT']);
}

$criteria = [
'SELECT' => [
QueryFunction::fromUnixtime(
Expand Down
Loading