Problem/Motivation
Within Open Social we've found some scenarios that can cause a table to be created in the database for a field, but the Search API does not properly track that this field was added to the index. This causes the table to be recreated every time a new item is added to the index which can cause the site to break by filling up the database with duplicate tables.
I've been able to reproduce this in our set-up with a specific field which is added to the index through a configuration override (I'm not sure if that's part of the issue or not, but I think the issue is in Search API code nonetheless)
I've been able to trace it to the indexItem field for the Database backend for search: https://git.drupalcode.org/project/search_api/-/blob/8.x-1.x/modules/sea...
This calls fieldsUpdated which will create the table and update db_info in the key value store https://git.drupalcode.org/project/search_api/-/blob/8.x-1.x/modules/sea...
I think the issue is though that indexItem itself retrieves db_info before calling fieldsUpdated: https://git.drupalcode.org/project/search_api/-/blob/8.x-1.x/modules/sea...
It will then later store these values again which do not have the changes created in fieldsUpdated: https://git.drupalcode.org/project/search_api/-/blob/8.x-1.x/modules/sea...
Steps to reproduce
Proposed resolution
Reload $db_info in indexItem after calling fieldsUpdated.
Remaining tasks
| Comment | File | Size | Author |
|---|---|---|---|
| #2 | 3324776-search_api-2.patch | 1.27 KB | kingdutch |
Comments
Comment #2
kingdutchComment #3
drunken monkeyThanks for reporting this issue!
Your analysis and patch seem spot-on. Merged it now – thanks a lot again!
And sorry it took me a while to reply.