Skip to content

[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
OCA:19.0from
bosd:19.0-imp-base_substate-cache-substate-type
Open

[19.0][IMP] base_substate: cache substate type lookup to avoid a query per computed field#1303
bosd wants to merge 1 commit into
OCA:19.0from
bosd:19.0-imp-base_substate-cache-substate-type

Conversation

@bosd

@bosd bosd commented Jun 18, 2026

Copy link
Copy Markdown
Contributor

Problem

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 that mixes in base.substate.mixin and has several computed fields, this means one redundant base.substate.type search 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 same SELECT ... 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:

  • add _get_substate_type_id, an @tools.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.

Notes

  • No functional change; the existing base_substate tests pass.
  • Caught while profiling a kanban on a custom model using the mixin: the per-computed-field base.substate.type searches were a measurable chunk of the query count.

…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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants