-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
fix(notificationtarget): handle duplicate targets when deleting notification recipients #22942
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
base: 11.0/bugfixes
Are you sure you want to change the base?
Conversation
…ication recipients
Rom1-B
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe we should add an SQL unique key?
In that case, we would need to clean up any potential duplicates during migration, just before adding this key.
|
I agree with Rom1; the issue can be resolved simply by adding a uniqueness key. The root cause of the problem lies in an internal SQL script used to add notifications/targets to instances. This script does not raise an error when attempting to add a target that already exists in GLPI, which results in duplicate entries in the database. |
install/migrations/update_11.0.5_to_11.0.6/notificationtargets.php
Outdated
Show resolved
Hide resolved
| ], [ | ||
| 'id' => '187', | ||
| 'items_id' => '1', | ||
| 'type' => '1', | ||
| 'notifications_id' => '71', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It doesn't seem that the error comes from the GLPI basic data, but from a hack on the instance, so I doubt we need to delete anything here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I removed the target because it was inserted twice (L4380 and L4610). I have to remove it, otherwise I get an error when installing a database.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK. However, that leaves a gap in the IDs.
Please correct the errors reported by the CIs and it should be OK.
| ], [ | ||
| 'id' => '187', | ||
| 'items_id' => '1', | ||
| 'type' => '1', | ||
| 'notifications_id' => '71', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK. However, that leaves a gap in the IDs.
Please correct the errors reported by the CIs and it should be OK.
install/mysql/glpi-empty.sql
Outdated
| PRIMARY KEY (`id`), | ||
| UNIQUE KEY `unicity` (`notifications_id`,`items_id`,`type`), | ||
| KEY `items` (`type`,`items_id`), | ||
| KEY `notifications_id` (`notifications_id`), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
According to getUselessKeys(), called by the --detect-useless-keys option, the index on notifications_id should be removed. This is what's causing the CI to fail. However, this index is relevant because some queries filter only by notifications_id, without using other columns. These queries will lose performance, but the impact is only measurable from 10,000 rows onward, which is likely rare. So, we can remove it, unless we prefer to modify getUselessKeys() to satisfy the CI.
| KEY `notifications_id` (`notifications_id`), |
What do you think? @cedric-anne @AdrienClairembault @trasher
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, KEY must be removed since it"s included in unicity.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It must be removed in the migration script as well
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
https://dev.mysql.com/doc/refman/8.4/en/multiple-column-indexes.html
If the table has a multiple-column index, any leftmost prefix of the index can be used by the optimizer to look up rows. For example, if you have a three-column index on (col1, col2, col3), you have indexed search capabilities on (col1), (col1, col2), and (col1, col2, col3).
Co-authored-by: Romain B. <8530352+Rom1-B@users.noreply.github.com>
AdrienClairembault
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Tests are failing.
Yes, because of #22942 (comment) |
Description
NotificationTargetTicket::getFromDBByCrit() expects to get one result, 2 found in query "SELECT id FROM glpi_notificationtargets WHERE glpi_notificationtargets.notifications_id = '83' AND glpi_notificationtargets.items_id = '3' AND glpi_notificationtargets.type = '1'". In ./src/CommonDBTM.php(437) #0 ./src/NotificationTarget.php(160): CommonDBTM->getFromDBByCrit() #1 ./src/NotificationTarget.php(551): NotificationTarget->getFromDBForTarget() #2 ./front/notificationtarget.form.php(40): NotificationTarget::updateTargets() #3 ./src/Glpi/Controller/LegacyFileLoadController.php(64): require('/mnt/diskhome/h...') #4 ./vendor/symfony/http-kernel/HttpKernel.php(181): Glpi\Controller\LegacyFileLoadController->__invoke() #5 ./vendor/symfony/http-kernel/HttpKernel.php(76): Symfony\Component\HttpKernel\HttpKernel->handleRaw() #6 ./vendor/symfony/http-kernel/Kernel.php(197): Symfony\Component\HttpKernel\HttpKernel->handle() #7 ./public/index.php(70): Symfony\Component\HttpKernel\Kernel->handle() #8 {main}Screenshots (if appropriate):