summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLester Caine <lester@lsces.co.uk>2026-05-21 12:36:34 +0100
committerLester Caine <lester@lsces.co.uk>2026-05-21 12:36:34 +0100
commit4a3fcb583cbe52466d2e935caf65f1103c196692 (patch)
treeab88b70bea0c2710edf29fd40860929bf998a489
parent6116768df56c3085073953e78e605752071116c4 (diff)
downloadsearch-4a3fcb583cbe52466d2e935caf65f1103c196692.tar.gz
search-4a3fcb583cbe52466d2e935caf65f1103c196692.tar.bz2
search-4a3fcb583cbe52466d2e935caf65f1103c196692.zip
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 <noreply@anthropic.com>
-rwxr-xr-xincludes/refresh_functions.php24
1 files 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();
}
}
}