Skip to content

Commit

Permalink
feat(user): optimize User::getFromDBbyDn() by adding user_dn_hash
Browse files Browse the repository at this point in the history
  • Loading branch information
ccailly committed Nov 30, 2023
1 parent bfbb43a commit 6230ed1
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 2 deletions.
46 changes: 46 additions & 0 deletions install/migrations/update_10.0.10_to_10.0.11/user.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
<?php

/**
* ---------------------------------------------------------------------
*
* GLPI - Gestionnaire Libre de Parc Informatique
*
* http://glpi-project.org
*
* @copyright 2015-2023 Teclib' and contributors.
* @copyright 2003-2014 by the INDEPNET Development Team.
* @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
*/

// Add user_dn_hash field
$migration->addField('glpi_users', 'user_dn_hash', 'varchar(255) GENERATED ALWAYS AS (sha2(`user_dn`,256)) VIRTUAL', [
'after' => 'user_dn',
]);

// Add user_dn_hash index
$migration->addKey('glpi_users', 'user_dn_hash');
4 changes: 3 additions & 1 deletion install/mysql/glpi-empty.sql
Original file line number Diff line number Diff line change
Expand Up @@ -7608,6 +7608,7 @@ CREATE TABLE `glpi_users` (
`password_forget_token` char(40) DEFAULT NULL,
`password_forget_token_date` timestamp NULL DEFAULT NULL,
`user_dn` text,
`user_dn_hash` varchar(255) GENERATED ALWAYS AS (sha2(`user_dn`,256)) VIRTUAL,
`registration_number` varchar(255) DEFAULT NULL,
`show_count_on_tabs` tinyint DEFAULT NULL,
`refresh_views` int DEFAULT NULL,
Expand Down Expand Up @@ -7684,7 +7685,8 @@ CREATE TABLE `glpi_users` (
KEY `groups_id` (`groups_id`),
KEY `users_id_supervisor` (`users_id_supervisor`),
KEY `auths_id` (`auths_id`),
KEY `default_requesttypes_id` (`default_requesttypes_id`)
KEY `default_requesttypes_id` (`default_requesttypes_id`),
KEY `user_dn_hash` (`user_dn_hash`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci ROW_FORMAT=DYNAMIC;


Expand Down
4 changes: 3 additions & 1 deletion src/User.php
Original file line number Diff line number Diff line change
Expand Up @@ -558,7 +558,9 @@ public function getFromDBbySyncField($value)
*/
public function getFromDBbyDn($user_dn)
{
return $this->getFromDBByCrit(['user_dn' => $user_dn]);
return $this->getFromDBByCrit([
'user_dn_hash' => hash('sha256', $user_dn)
]);
}

/**
Expand Down

0 comments on commit 6230ed1

Please sign in to comment.