From 4a3fcb583cbe52466d2e935caf65f1103c196692 Mon Sep 17 00:00:00 2001 From: Lester Caine Date: Thu, 21 May 2026 12:36:34 +0100 Subject: Wrap insert_index() in transaction to prevent stuck Firebird locks Uncaught duplicate-key exception during search indexing left Firebird transactions uncommitted, holding locks that blocked subsequent page reads. StartTrans/CompleteTrans/RollbackTrans ensures the transaction is always closed cleanly regardless of INSERT failure. Co-Authored-By: Claude Sonnet 4.6 --- includes/refresh_functions.php | 24 +++++++++++++++--------- 1 file changed, 15 insertions(+), 9 deletions(-) diff --git a/includes/refresh_functions.php b/includes/refresh_functions.php index cb5f0bd..9eb9740 100755 --- a/includes/refresh_functions.php +++ b/includes/refresh_functions.php @@ -122,15 +122,21 @@ function delete_index ($pContentId) { function insert_index( &$words, $location, $pContentId ) { global $gBitSystem; if( !empty( $pContentId ) ) { - delete_index($pContentId); - $now = $gBitSystem->getUTCTime(); - foreach ($words as $key=>$value) { - if (strlen($key) >= $gBitSystem->getConfig( 'search_min_wordlength') ) { - // todo: stopwords + common words. - $query = "INSERT INTO `" . BIT_DB_PREFIX . "search_index` - (`content_id`,`searchword`,`i_count`,`last_update`) values (?,?,?,?)"; - $gBitSystem->mDb->query($query, [ $pContentId, $key, (int) $value, $now ]); - } // What happened to location? + try { + $gBitSystem->mDb->StartTrans(); + delete_index($pContentId); + $now = $gBitSystem->getUTCTime(); + foreach ($words as $key=>$value) { + if (strlen($key) >= $gBitSystem->getConfig( 'search_min_wordlength') ) { + // todo: stopwords + common words. + $query = "INSERT INTO `" . BIT_DB_PREFIX . "search_index` + (`content_id`,`searchword`,`i_count`,`last_update`) values (?,?,?,?)"; + $gBitSystem->mDb->query($query, [ $pContentId, $key, (int) $value, $now ]); + } // What happened to location? + } + $gBitSystem->mDb->CompleteTrans(); + } catch (\Exception $e) { + $gBitSystem->mDb->RollbackTrans(); } } } -- cgit v1.3