[19.0][IMP] base_substate: cache substate type lookup to avoid a query per computed field#1303
Open
bosd wants to merge 1 commit into
Open
[19.0][IMP] base_substate: cache substate type lookup to avoid a query per computed field#1303bosd wants to merge 1 commit into
bosd wants to merge 1 commit into
Conversation
…computed field `base.substate.mixin._compute_field_value` runs on every computed-field computation and calls `_get_substate_type()`, which issues a `base.substate.type` search each time. On a model with several computed fields this means one redundant search per computed field on every record read -- clearly visible on list/kanban loads of such models (e.g. several `base_substate_type` SELECTs for a single grouped read). The substate type for a model is technical configuration data that effectively never changes at runtime, so cache the lookup: - add `_get_substate_type_id`, an `@ormcache`-d helper keyed on the model name; - `_get_substate_type` now browses that cached id (return value unchanged, so existing overrides keep working); - clear the cache on `base.substate.type` create / model-change write / unlink. No functional change; existing tests pass.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
base.substate.mixin._compute_field_valueruns on every computed-field computation and calls_get_substate_type(), which issues abase.substate.typesearch each time.On a model that mixes in
base.substate.mixinand has several computed fields, this means one redundantbase.substate.typesearch per computed field on every record read. It is very visible when profiling list/kanban loads of such models — a single grouped read fires the sameSELECT ... FROM base_substate_type ...many times.Change
The substate type for a given model is technical configuration data that effectively never changes at runtime, so the lookup is cached:
_get_substate_type_id, an@tools.ormcache-d helper keyed on the model name;_get_substate_typenow browses that cached id — return value unchanged, so existing overrides keep working;base.substate.typecreate / model-change write / unlink.Notes
base_substatetests pass.base.substate.typesearches were a measurable chunk of the query count.