Problem/Motivation
I've had quite some trouble with the i18n_field integration on a site with lot's of field / field instances.
Every time an entity related configuration was changed (imagine entityforms) and hence the entity_property_info
cache was cleared I've got thousands of database queries to fetch field related translations.
This happened for every enabled language and often multiple times at once - pretty much throwing the database / site in a death spin.
Proposed resolution
- Add a locking to these expensive functions to avoid stampeding.
The patch adds a locking toi18n_field_i18n_object_info_alter()
- the other lock should be located in the entity module inentity_get_property_info()
, patch there follows.
- Add a cache priming when we know an expensive function is about to run.
Even the "non caching" default classi18n_string_textgroup_default
uses an object instance specific cache fori18n_string_textgroup_default::multiple_translation_search()
andi18n_string_textgroup_default::load_strings()
. We can call these functions with no conditions, prior to expensive functions, to fetch all translations at once. Potentially reducing hundreds of db requests to about two.
Attention: This relies on following patch to work properly: #2986171: i18n_string_textgroup_cached::multiple_cache_get() not properly filtering return value
- Inject translations instead rebuilding the whole cache.
i18n_field_i18n_object_info_alter()
- it looks like we can inject the translations rather than flushing the whole cache again.
These adjustments showed massive improvements on the page that suffered from the heavy database load.
Remaining tasks
Reviews needed.
User interface changes
None
API changes
None
Data model changes
None
Comment | File | Size | Author |
---|---|---|---|
i18n-optimize-cache-usage-and-avoid-stampeding.patch | 3.67 KB | das-peter |
Comments
Comment #2
joseph.olstadCode looks good. I have a comment for the related one though.
Comment #3
joseph.olstadOk, looks good, das-peter, feel free to put this in the dev branch, let it simmer in there for a bit.
Comment #5
das-peter CreditAttribution: das-peter at Cando commentedHere we go :) Committed & pushed.
@joseph.olstad Thank you very much for your feedback - highly appreciated.