Further modularize syncing of tags with fulltext search index

This commit is contained in:
Joshua Ramon Enslin 2023-08-15 15:55:48 +02:00
parent cb6d0d7b06
commit f27d0900ae
Signed by: jrenslin
GPG Key ID: 46016F84501B70AE

View File

@ -137,17 +137,11 @@ final class NodaTagFulltextSyncManticore {
} }
/** /**
* Runs a full sync. * Synchronizes base entries.
*
* @param MDMysqli $mysqli_noda Connection to MySQL DB.
* @param MDMysqli $mysqli_manticore Connection to Manticore DB.
* @param string $databasename Name of the main noda database.
* *
* @return void * @return void
*/ */
public static function runFullSync(MDMysqli $mysqli_noda, MDMysqli $mysqli_manticore, string $databasename):void { public static function runFullSyncForBaseEntries(MDMysqli $mysqli_noda, MDMysqli $mysqli_manticore, string $databasename):void {
$mysqli_manticore->do_update_query_large("TRUNCATE RTINDEX `" . $databasename . "_tag`");
// Sync tags // Sync tags
@ -159,22 +153,24 @@ final class NodaTagFulltextSyncManticore {
$mysqli_manticore->autocommit(false); $mysqli_manticore->autocommit(false);
while ($cur = $result->fetch_assoc()) { while ($cur = $result->fetch_row()) {
$tag_id = (int)$cur[0];
$mysqli_manticore->query("INSERT INTO `" . $databasename . "_tag` $mysqli_manticore->query("INSERT INTO `" . $databasename . "_tag`
(`entry_id`, `language`, `name`, `description`, `timestamp`) (`entry_id`, `language`, `name`, `description`, `timestamp`)
VALUES VALUES
(" . $cur['tag_id'] . ", (" . $tag_id . ",
'', '',
'" . $mysqli_manticore->escape_string($cur['tag_name']) . "', '" . $mysqli_manticore->escape_string($cur[1]) . "',
'" . $mysqli_manticore->escape_string($cur['tag_anmerkung']) . "', '" . $mysqli_manticore->escape_string($cur[2]) . "',
'" . strtotime($mysqli_manticore->escape_string($cur['tag_erfasst_am'])) . "')"); '" . strtotime($mysqli_manticore->escape_string($cur[3])) . "')");
if ($mysqli_manticore->error) { if ($mysqli_manticore->error) {
throw new Exception($mysqli_manticore->error); throw new Exception($mysqli_manticore->error);
} }
MDConsole::write("Wrote {$cur['tag_id']}"); MDConsole::write("Wrote #" . $tag_id);
++$i; ++$i;
if ($i === self::FULL_SYNC_COMMIT_AFTER) { if ($i === self::FULL_SYNC_COMMIT_AFTER) {
$mysqli_manticore->commit(); $mysqli_manticore->commit();
@ -186,31 +182,42 @@ final class NodaTagFulltextSyncManticore {
$result->close(); $result->close();
$mysqli_manticore->commit(); $mysqli_manticore->commit();
$mysqli_manticore->autocommit(true);
// Sync translations }
/**
* Synchronizes translated entries.
*
* @return void
*/
public static function runFullSyncForTranslatedEntries(MDMysqli $mysqli_noda, MDMysqli $mysqli_manticore, string $databasename):void {
$result = $mysqli_noda->do_read_query("SELECT `tag_id`, `trans_language`, $result = $mysqli_noda->do_read_query("SELECT `tag_id`, `trans_language`,
`trans_name`, `trans_description`, `trans_last` `trans_name`, `trans_description`, `trans_last`
FROM `" . $databasename . "`.`tag_translation`"); FROM `" . $databasename . "`.`tag_translation`");
$mysqli_manticore->autocommit(false);
$i = 0; $i = 0;
while ($cur = $result->fetch_assoc()) { while ($cur = $result->fetch_row()) {
$tag_id = $cur[0];
$mysqli_manticore->query("INSERT INTO `" . $databasename . "_tag` $mysqli_manticore->query("INSERT INTO `" . $databasename . "_tag`
(`entry_id`, `language`, `name`, `description`, `timestamp`) (`entry_id`, `language`, `name`, `description`, `timestamp`)
VALUES VALUES
(" . $cur['tag_id'] . ", (" . $tag_id . ",
'" . $mysqli_manticore->escape_string($cur['trans_language']) . "', '" . $mysqli_manticore->escape_string($cur[1]) . "',
'" . $mysqli_manticore->escape_string($cur['trans_name']) . "', '" . $mysqli_manticore->escape_string($cur[2]) . "',
'" . $mysqli_manticore->escape_string($cur['trans_description']) . "', '" . $mysqli_manticore->escape_string($cur[3]) . "',
'" . strtotime($mysqli_manticore->escape_string($cur['trans_last'])) . "')"); '" . strtotime($mysqli_manticore->escape_string($cur[4])) . "')");
if ($mysqli_manticore->error) { if ($mysqli_manticore->error) {
throw new Exception($mysqli_manticore->error); throw new Exception($mysqli_manticore->error);
} }
MDConsole::write("Wrote {$cur['tag_id']}"); MDConsole::write("Wrote #" . $tag_id);
++$i; ++$i;
if ($i === self::FULL_SYNC_COMMIT_AFTER) { if ($i === self::FULL_SYNC_COMMIT_AFTER) {
$mysqli_manticore->commit(); $mysqli_manticore->commit();
@ -223,4 +230,25 @@ final class NodaTagFulltextSyncManticore {
$mysqli_manticore->autocommit(true); $mysqli_manticore->autocommit(true);
} }
/**
* Runs a full sync.
*
* @param MDMysqli $mysqli_noda Connection to MySQL DB.
* @param MDMysqli $mysqli_manticore Connection to Manticore DB.
* @param string $databasename Name of the main noda database.
*
* @return void
*/
public static function runFullSync(MDMysqli $mysqli_noda, MDMysqli $mysqli_manticore, string $databasename):void {
$mysqli_manticore->do_update_query_large("TRUNCATE RTINDEX `" . $databasename . "_tag`");
self::runFullSyncForBaseEntries($mysqli_noda, $mysqli_manticore, $databasename);
// Sync translations
self::runFullSyncForTranslatedEntries($mysqli_noda, $mysqli_manticore, $databasename);
}
} }