Skip to content

[19.0][IMP][WIP] endpoint_route_handler: memoize route version per request#140

Open
JordiBForgeFlow wants to merge 1 commit into
OCA:19.0from
ForgeFlow:19.0-imp-endpoint_route_handler-version-memo
Open

[19.0][IMP][WIP] endpoint_route_handler: memoize route version per request#140
JordiBForgeFlow wants to merge 1 commit into
OCA:19.0from
ForgeFlow:19.0-imp-endpoint_route_handler-version-memo

Conversation

@JordiBForgeFlow

Copy link
Copy Markdown
Member

_endpoint_route_last_version() is part of the routing_map ormcache key, so it runs on every routing map access -- e.g. once per url_for while rendering a website page, which adds up to dozens of identical 'SELECT last_value FROM endpoint_route_version' round-trips per page on content-heavy sites. The version cannot change within a request: memoize it on the request object.

@OCA-git-bot

Copy link
Copy Markdown
Contributor

Hi @simahawk,
some modules you are maintaining are being modified, check this out!

@OCA-git-bot OCA-git-bot added series:19.0 mod:endpoint_route_handler Module endpoint_route_handler labels Jun 4, 2026
@JordiBForgeFlow JordiBForgeFlow changed the title [19.0][IMP] endpoint_route_handler: memoize route version per request [19.0][IMP][WIP] endpoint_route_handler: memoize route version per request Jun 4, 2026
@MiquelRForgeFlow MiquelRForgeFlow force-pushed the 19.0-imp-endpoint_route_handler-version-memo branch 3 times, most recently from 76db789 to 7319791 Compare June 5, 2026 11:37
_endpoint_route_last_version() is part of the routing_map ormcache key,
so it runs on every routing map access -- e.g. once per url_for while
rendering a website page, which adds up to dozens of identical
'SELECT last_value FROM endpoint_route_version' round-trips per page on
content-heavy sites. The version cannot change within a request:
memoize it on the request object.
@MiquelRForgeFlow MiquelRForgeFlow force-pushed the 19.0-imp-endpoint_route_handler-version-memo branch from 7319791 to 5278835 Compare June 5, 2026 11:40
request = http.request
if not request:
return cls._get_routing_map_last_version(http.request.env)
version = request.__dict__.get(cls._endpoint_route_version_attr)

@simahawk simahawk Jul 1, 2026

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

are we sure there's no better way than accessing __dict__? I tend to think the mocking is wrong somehow.

You could deleted it beforehand:

>>> from unittest.mock import MagicMock
>>> my_mock = MagicMock()
>>> del my_mock.missing_attr
>>> getattr(my_mock, "missing_attr", "default")
'default'
>>> getattr(my_mock, "missing_attr", "default")
'default'
>>> my_mock.missing_attr = 1
>>> getattr(my_mock, "missing_attr", "default")
1

Is that what you are looking for?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

mod:endpoint_route_handler Module endpoint_route_handler series:19.0

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants