Skip to content

Commit

Permalink
fix(Tinebase/Fulltext): max blob size needs to be reduced some more
Browse files Browse the repository at this point in the history
-> we set it to 80% of max_allowed_packet

... mariadb/mysql prevent writing of fulltext index otherwise
  • Loading branch information
pschuele committed Oct 9, 2024
1 parent 289bb7f commit 1b49e31
Showing 1 changed file with 18 additions and 5 deletions.
23 changes: 18 additions & 5 deletions tine20/Tinebase/Fulltext/Indexer.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,9 +71,9 @@ private function __construct()
}

/**
* @return float|int
* @return int
*/
public static function getMaxBlobSize()
public static function getMaxBlobSize(): int
{
$maxBlobSize = 0;

Expand All @@ -87,8 +87,9 @@ public static function getMaxBlobSize()
if ($maxPacketSize > 0 && ($maxBlobSize === 0 || $maxPacketSize < $maxBlobSize)) {
$maxBlobSize = $maxPacketSize;
}
// reduce by more chars because we send more than just the blob (ID, ...)
if ($maxBlobSize > 0) {
$maxBlobSize -= 64*1024;
$maxBlobSize = round($maxBlobSize * 0.8);
}
}

Expand Down Expand Up @@ -116,7 +117,11 @@ public function addFileContentsToIndex($_id, $_fileName)
if (Tinebase_Core::isLogLevel(Tinebase_Log::NOTICE))
Tinebase_Core::getLogger()->notice(__METHOD__ . '::' . __LINE__ . ' Truncating full text blob for id '
. $_id . ' to max blob size');
$blob = mb_substr($blob, 0, $this->_maxBlobSize);
$blob = substr($blob, 0, $this->_maxBlobSize);
if (Tinebase_Core::isLogLevel(Tinebase_Log::DEBUG)) {
Tinebase_Core::getLogger()->notice(__METHOD__ . '::' . __LINE__ . ' Blobsize after reduction: '
. strlen($blob));
}
}

if (Tinebase_Core::isLogLevel(Zend_Log::DEBUG)) {
Expand All @@ -128,7 +133,15 @@ public function addFileContentsToIndex($_id, $_fileName)

$db = Tinebase_Core::getDb();
$db->delete(SQL_TABLE_PREFIX . 'external_fulltext', $db->quoteInto($db->quoteIdentifier('id') . ' = ?', $_id));
$db->insert(SQL_TABLE_PREFIX . 'external_fulltext', array('id' => $_id, 'text_data' => $blob));
try {
$db->insert(SQL_TABLE_PREFIX . 'external_fulltext', array('id' => $_id, 'text_data' => $blob));
} catch (Zend_Db_Statement_Exception $zdse) {
if (Tinebase_Core::isLogLevel(Zend_Log::WARN)) {
Tinebase_Core::getLogger()->warn(__METHOD__ . '::' . __LINE__ . ' Could not index file '
. $_fileName
. ' error: ' . $zdse->getMessage());
}
}
}

/**
Expand Down

0 comments on commit 1b49e31

Please sign in to comment.