[TikiWiki-commits] [Git][tikiwiki/tiki][30.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 | <6a1d31be54915_38193fc0380b9@gitlab-sidekiq-low-urgency-cpu-bound-v2-57bc5b685d-zttjq.mail> |
Victor Emanouilov pushed to branch 30.x at Tiki Wiki CMS Groupware / Tiki
Commits:
ff3a55b1 by Victor Emanouilov at 2026-06-01T10:16:08+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
=====================================
@@ -135,9 +135,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/ff3a55b1fbbed03b3a1490372f8fd0b4c11d04fc
--
View it on GitLab: https://gitlab.com/tikiwiki/tiki/-/commit/ff3a55b1fbbed03b3a1490372f8fd0b4c11d04fc
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