]> git.mxchange.org Git - friendica.git/commitdiff
Ensure identifier uniqueness in Disposable FullTextSearch
authorHypolite Petovan <hypolite@mrpetovan.com>
Sat, 27 Jan 2024 16:33:28 +0000 (11:33 -0500)
committerHypolite Petovan <hypolite@mrpetovan.com>
Sat, 27 Jan 2024 16:33:28 +0000 (11:33 -0500)
src/Database/DisposableFullTextSearch.php

index 3516080f767c03fb8bdbb2fd0b98b10609827c57..fb8ce900d59e0d62e158811fc6bf53cdddb60cf7 100644 (file)
@@ -37,12 +37,12 @@ class DisposableFullTextSearch
        {
                $this->db = $database;
 
-               // Unique identifier generation. Two DisposableFullTextSearch object should never have the same as the first object destruction
-               // would delete both check-full-text-search rows, before the second object destruction is called, leading to unexpected behavior.
-               // Maximum value is indicated by the INT UNSIGNED type of the check-full-text-search.pid field
-               $this->identifier = random_int(0, pow(2, 32) - 1);
-
-               $this->db->insert('check-full-text-search', ['pid' => $this->identifier, 'searchtext' => $haystack], Database::INSERT_UPDATE);
+               do {
+                       // Unique identifier generation. Two DisposableFullTextSearch object should never have the same as the first object destruction
+                       // would delete both check-full-text-search rows before the second object destruction is called, leading to unexpected behavior.
+                       // Maximum value is indicated by the INT UNSIGNED type of the check-full-text-search.pid field
+                       $this->identifier = random_int(0, pow(2, 32) - 1);
+               } while($this->db->insert('check-full-text-search', ['pid' => $this->identifier, 'searchtext' => $haystack]));
        }
 
        public function __destruct()