Bug Description
Race condition can occur when multiple requests simultaneously try to trigger the option_update/add_option code to bump altis_search_index_version from 2 to 3 in https://github.com/humanmade/altis-enhanced-search/blob/master/inc/namespace.php#L566-L573. Option ends up in notoptions cache despite existing in database as version 3.
When this happens every subsequent request triggers:
get_option('altis_search_index_version', null) returns null (due to notoptions)
- Code in
filter_index_name() checks if version is 2, then calls set_index_version(3)
- This causes
update_option() which attempts INSERT (since cache thinks option doesn't exist) and make all the queries go to the writer db
Steps to Reproduce and Code Sample
Enable ElasticSearch on a high traffic site
Expected Behaviour
The altis_search_index_version option should remain properly cached and not fall into notoptions when it exists in the database. Don’t update the DB on viewer traffic.
Additional Info
More info: https://hmn.slack.com/archives/C0A2F2VC58A/p1765305934093979