[TikiWiki-commits] [Git][tikiwiki/tiki][29.x] [FIX] Manticore: generate document IDs on our own to prevent insertion of...

"Victor Emanouilov \(@kroky\) via TikiWiki-cvs" <[email protected]>
Newsgroups gmane.comp.cms.tiki.cvs
Message-ID <6a1d31c6cfe69_38193cb45004c@gitlab-sidekiq-low-urgency-cpu-bound-v2-57bc5b685d-n6wfn.mail>

Victor Emanouilov pushed to branch 29.x at Tiki Wiki CMS Groupware / Tiki


Commits:
8acd73aa by Victor Emanouilov at 2026-06-01T10:16:16+03:00
[FIX] Manticore: generate document IDs on our own to prevent insertion of duplicates for the same type/id pairs - some race conditions with incremental index

- - - - -


2 changed files:

- lib/core/Search/Manticore/Index.php
- lib/core/Search/Manticore/PdoClient.php


Changes:

=====================================
lib/core/Search/Manticore/Index.php
=====================================
@@ -133,9 +133,21 @@ class Index implements \Search_Index_Interface, \Search_Index_QueryRepository
         }
         $normalData['tracker_fields_json'] = json_encode($jsonFields);
 
+        $normalData['id'] = self::generateDocumentId($normalData['object_type'], $normalData['object_id']);
+
         return $normalData;
     }
 
+    /**
+     * Generate document ID from unique representation of object_type and object_id.
+     * Used to fix duplicate document insertion bugs using REPLACE INTO.
+     */
+    public static function generateDocumentId(string $objectType, string $objectId): int
+    {
+        $hash = hash('xxh128', "$objectType $objectId", true);
+        return unpack('J', substr($hash, 0, 8))[1] & 0x7FFFFFFFFFFFFFFF;
+    }
+
     private function generateMapping($type, $data)
     {
         global $prefs;


=====================================
lib/core/Search/Manticore/PdoClient.php
=====================================
@@ -330,10 +330,10 @@ class PdoClient
             $values .= ', ' . implode(', ', $array_values);
         }
         if ($this->dataBuffer) {
-            $this->dataBuffer->setPrefix("INSERT INTO $index ($keys) VALUES ");
+            $this->dataBuffer->setPrefix("REPLACE INTO $index ($keys) VALUES ");
             $this->dataBuffer->push('(' . $values . ')');
         } else {
-            $this->prepareAndExecuteWithRetry("INSERT INTO $index ($keys) VALUES (" . $values . ")");
+            $this->prepareAndExecuteWithRetry("REPLACE INTO $index ($keys) VALUES (" . $values . ")");
         }
     }
 



View it on GitLab: https://gitlab.com/tikiwiki/tiki/-/commit/8acd73aa93c5f58602bdebcfb135c92acf1dcce0

-- 
View it on GitLab: https://gitlab.com/tikiwiki/tiki/-/commit/8acd73aa93c5f58602bdebcfb135c92acf1dcce0
You're receiving this email because of your account on gitlab.com. Manage all notifications: https://gitlab.com/-/profile/notifications | Help: https://gitlab.com/help

_______________________________________________
TikiWiki-cvs mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/tikiwiki-cvs
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.