Skip to content

Commit

Permalink
Try inserting search keywords 3 times
Browse files Browse the repository at this point in the history
fixes #15221
  • Loading branch information
brandonkelly committed Nov 28, 2024
1 parent 2ad3709 commit e8082f6
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
## Unreleased

- Fixed an error that could occur when duplicating an element with an Assets field that had a dynamic subpath. ([#16214](https://github.com/craftcms/cms/issues/16214))
- Reduced the likelihood of a deadlock error occurring when updating search indexes. ([#15221](https://github.com/craftcms/cms/issues/15221))

## 4.13.3 - 2024-11-22

Expand Down
16 changes: 15 additions & 1 deletion src/services/Search.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
use craft\search\SearchQueryTermGroup;
use Throwable;
use yii\base\Component;
use yii\db\Exception;
use yii\db\Expression;
use yii\db\Schema;

Expand Down Expand Up @@ -483,7 +484,20 @@ private function _indexKeywords(ElementInterface $element, string $keywords, ?st
}

// Insert/update the row in searchindex
Db::insert(Table::SEARCHINDEX, $columns);
for ($try = 0; $try < 3; $try++) {
try {
Db::insert(Table::SEARCHINDEX, $columns);
return;
} catch (Exception $e) {
if (str_contains($e->getPrevious()?->getMessage(), 'deadlock')) {
// A gap lock was probably hit. Try again in one second
// https://github.com/craftcms/cms/issues/15221
sleep(1);
} else {
throw $e;
}
}
}
}

/**
Expand Down

0 comments on commit e8082f6

Please sign in to comment.