diff --git a/CHANGELOG.md b/CHANGELOG.md index 6c69fde..1f4593b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,12 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](http://keepachangelog.com/) and this project adheres to [Semantic Versioning](http://semver.org/). +## [Unreleased] + +### Fixed + +- Performance: remove an unused query and a CSRF token per tree group, read only the displayed columns, load `treeview.css` on the tree frame only, add an index on the preferences `users_id` column + ## [1.20.4] - 2026-11-05 ### Fixed diff --git a/hook.php b/hook.php index a706ba3..6e6d870 100644 --- a/hook.php +++ b/hook.php @@ -109,12 +109,18 @@ function plugin_treeview_install() `id` int {$default_key_sign} NOT NULL auto_increment, `users_id` int {$default_key_sign} NOT NULL default '0' COMMENT 'RELATION to glpi_users (id)', `show_on_load` int NOT NULL default '0', - PRIMARY KEY (`id`) + PRIMARY KEY (`id`), + KEY `users_id` (`users_id`) ) ENGINE=InnoDB DEFAULT CHARSET={$default_charset} COLLATE={$default_collation} ROW_FORMAT=DYNAMIC;"; $DB->doQuery($query); } + // Preferences are looked up by user on each profile change + $migration = new Migration(PLUGIN_TREEVIEW_VERSION); + $migration->addKey('glpi_plugin_treeview_preferences', 'users_id'); + $migration->executeMigration(); + // No autoload when plugin is not activated require_once __DIR__ . '/inc/profile.class.php'; diff --git a/inc/config.class.php b/inc/config.class.php index ebb8c0b..3034565 100644 --- a/inc/config.class.php +++ b/inc/config.class.php @@ -329,17 +329,22 @@ public function getNodesFromDb() $itemtable = getTableForItemType($type); $criteria = [ - 'FROM' => $itemtable, - 'WHERE' => [ + 'SELECT' => [$itemtable . '.id', $itemtable . '.name'], + 'FROM' => $itemtable, + 'WHERE' => [ 'locations_id' => $r['id'], ], - 'ORDER' => [$itemtable . '.name'], + 'ORDER' => [$itemtable . '.name'], ]; if ($item->maybeTemplate()) { $criteria['WHERE']['is_template'] = 0; } + if ($item->isField('otherserial')) { + $criteria['SELECT'][] = $itemtable . '.otherserial'; + } + if ($item->maybeDeleted()) { $criteria['WHERE']['is_deleted'] = 0; } @@ -354,19 +359,8 @@ public function getNodesFromDb() $pid = $tv_id; $field_num = 3; - $result_location = $DB->request([ - 'SELECT' => ['completename'], - 'FROM' => 'glpi_locations', - 'WHERE' => ['id' => $r['id']], - ]); - - foreach ($result_location as $row) { - $name_location = $row['completename']; - } - $value = $r['id']; - $token = Session::getNewCSRFToken(); - $getParam = sprintf('?is_deleted=0&criteria[0][field]=%d&criteria[0][searchtype]=equals&criteria[0][value]=%s&search=Rechercher&start=0&_glpi_csrf_token=%s', $field_num, $value, $token); + $getParam = sprintf('?is_deleted=0&criteria[0][field]=%d&criteria[0][searchtype]=equals&criteria[0][value]=%s&search=Rechercher&start=0', $field_num, $value); $searchUrl = Toolbox::getItemTypeSearchURL($type) . $getParam; diff --git a/public/left.php b/public/left.php index befb9c4..021eb06 100644 --- a/public/left.php +++ b/public/left.php @@ -42,6 +42,12 @@ Html::includeHeader('TreeView'); echo ""; +// Only this page needs the explorer bar styles, they are not loaded on the other GLPI pages +echo sprintf( + "", + $CFG_GLPI['root_doc'], + PLUGIN_TREEVIEW_VERSION, +); // Title bar echo '
'; echo '
'; diff --git a/setup.php b/setup.php index fe207f7..255eb1c 100644 --- a/setup.php +++ b/setup.php @@ -69,7 +69,7 @@ function plugin_init_treeview() && $_SESSION['glpi_plugin_treeview_loaded'] == 1 && class_exists(PluginTreeviewConfig::class) ) { - foreach (PluginTreeviewConfig::getTypes() as $type) { + foreach (PluginTreeviewConfig::getTypes(true) as $type) { $PLUGIN_HOOKS[Hooks::ITEM_UPDATE]['treeview'][$type] = 'plugin_item_update_treeview'; $PLUGIN_HOOKS[Hooks::ITEM_DELETE]['treeview'][$type] = 'plugin_treeview_reload'; $PLUGIN_HOOKS[Hooks::ITEM_RESTORE]['treeview'][$type] = 'plugin_treeview_reload'; @@ -95,9 +95,6 @@ function plugin_init_treeview() $config = new PluginTreeviewConfig(); $config->hideTreeview(); } - - // Add specific files to add to the header : javascript or css - $PLUGIN_HOOKS[Hooks::ADD_CSS]['treeview'] = 'css/treeview.css'; } // Config page