f1abc4e4f352f0efdecddc2ed8a9d7cdf9a6bf98
4
Commits
| Author | SHA1 | Message | Date | |
|---|---|---|---|---|
|
|
6d5d234f15 |
[IMP] base: better ormcache management
1. move cache to _get_asset_paths
The `_get_asset_content` cache has many cache key that are related to a
posprocessing of the `_get_asset_paths` result, the heavy part of this
method. Moving the cache to _get_asset_content will have the benefit
to create less duplicates entries in the ormcache as well as less cache
miss.
To simplify even further, the css and js parameters are removed since
they only filter the output of get_paths, the heavy part of globing the
file will be done before that. Anyway, they are both true when called
from _get_asset_content, and the only other call, in
`_get_related_bundle` don't really need to filter them since it is not
a critical part regarding performance, and the funtional result will
stay the same.
The initial orm cache key was using `_get_template_cache_keys`, a little
overkill and possibly creating duplicates entries again. The only
context key needed is website_id for `_get_related_assets`.
Note that it is not really enough, the orm cache key should actually
contain `request.session.get('force_website_id')` as well has
`request.httprequest.host`. This will be addressed latter since a nicer
solution would be to have website_id as a unique parameter computed
earlier.
2. better _get_asset_paths cache key
The orm cache key was simplified in previous point but there is still
one concern, the website_id depends on more parameters than that:
- request.session.get('force_website_id')
- request.httprequest.host
- existing websites
The idea here is to call `get_current_website` instead of using all
parameters that could define the webiste.
In the same spirit of `_get_template_cache_keys` `_assets_path_params`
can be overriden to give extra params that are usefull to list assets
path. Those params are computed before entering the method
`_get_asset_paths`. This may latter put at a higher level latter, in
get_asset_node, to simplify the _generate_asset_nodes_cache key.
3. better assets_node caches key
The main purpose of this part is to improve ormcache containing assets
nodes. The ormcache key contains
- to much context key
- missing session/host/env info
- unwanted boolean options.
- keys leading to the same cache value
The main goal being to reduce the size of the cache keys, decrease the
number of cache entries and improve the cache hit.
This will also make the behaviour more coherent and hopefully less bug
prone because of mismatch in parameters.
The main reason of the orm cache is the slowness of the validation of
the assets. This includes:
- listing files (dedicated orm cache)
- computing version
The cache key was depending on
- `debug`
The only relevant value for debug is "contains assets"
We dont need to differ between debug='', debug='1', debug='test',
and 'debug=assets', 'debug=tests,assets', ...
- `defer_load`, `lazy_load`, `media`
Those values are only useful to generate html node, a leightweight
operations that does not really needs to be in cache. `media` was also
used in the generation but it looks useless if we have the media on the
node. THIS NEEDS TO BE VALIDATED but in any case, since media is not
used to generate the url, it doesn't make sence to use it in the
generation.
The main idea to remove them from the ormcache key is simply to generate
the nodes outide the ormcached values.
-`async_load`
This one is similar to `defer_load` and `lazy_load` but it looks like
it wasn't used anymore. This was simply removed
- context.get('lang')
The only information needed is the direction, rtl or ltr. This means
en and fr languages, despite sharing the same css assets, will duplicate
the ormcache entries.
-`_get_template_cache_keys`
Only the lang and webiste where really relevant in this flow. Other
keys are actually useless in this flow.
Some information used in the generation where not in the orm cache key
- `self.env.user.lang` if there is no lang in the context
- `request.session.get('force_website_id')`
- `request.httprequest.host`
- ...
The proposed solution is to:
- extract any informùation needed from thecontext, request, environment
before entering the ormcache, reduce it to the minimal possible set of
values needed
```
rtl = self.env['res.lang']._lang_get_direction(self.env.context.get('lang') or self.env.user.lang) == 'rtl'
assets_params = self.env['ir.asset']._get_assets_params() # website_id
debug_assets = debug and 'assets' in debug
```
and remove a leightweight part of the logic
```
def _get_asset_nodes(self, bundle, css=True, js=True, debug=False, defer_load=False, lazy_load=False, media=None):
links = self._get_asset_links(bundle, css=css, js=js, debug=debug)
return self._links_to_nodes(links, defer_load=defer_load, lazy_load=lazy_load, media=media)
```
Where _get_asset_links is the cached part, and _links_to_nodes is the
lightweight part generating the nodes based on the `defer_load`, ....
Additionnal notes:
- data-asset-version and data-asset-bundle are removed from the node
since they don't seem to be used anymore since
|
||
|
|
5594d8f191 |
[IMP] base, *: speedup assets unique computation
One of the most costly part of a page loading when the ormcache is cold is computing the assets node, the unique identifier of an attachment to validate whether the existing attachment is still valid with the current version of the static files. This operation needs to glob assets path in the filesystem, get the modification date, check attachments, ... Right now this task is not really optimized and can take some time because of an excessive number of glob on the filesystem, unnecessary exists to define absolute path, double computation of file list and modified times when getting js and css bundle separately, ... A list of modifications mainly discussed in the pr message are made with this commit to speedup things. - split css and js unique - prepare api for an in memory glob - change api to propagate absolute path and meta information through `ir.asset._get_paths`-> _get_asset_paths -> `_get_asset_content` -> `AssetsBundle` closes odoo/odoo#121159 Signed-off-by: Xavier Dollé (xdo) <xdo@odoo.com> |
||
|
|
503ed05029 |
[IMP] tests: add generic Basecase.start for patch
Using patcher.start() can easily lead to incorrect cleanup. -> after a copy paste, patcher is working, but stop is forgotten -> stop is present, but won't be called if something fails during the test This commit add an utility `start(patcher)` to always have the add cleanup. Using a standard way to start the patcher with an automated addCleanup should prevent this kind of mistake. This is why this commit also replaces all valid patch.start() (followed immediately by a addCleanup) closes odoo/odoo#102873 X-original-commit: 7d5a193d86316965a0908c65cfacfb607dc3f3ad Related: odoo/enterprise#32618 Signed-off-by: Christophe Monniez (moc) <moc@odoo.com> Signed-off-by: Xavier Dollé (xdo) <xdo@odoo.com> |
||
|
|
5410b7c238 |
[IMP] base/web: XML templates are added into the asset bundles.
XML files are now declared in python module manifests. During the qweb 't-call-asset' directive, assetbundle will fetch the declared xml files, apply the inheritance (t-inherit) and create a javascript service (for eg: 'web.assets_backend.bundle.xml') which is added at the end of the *.js mimifier file. When the debug mode is activated, comments are added in the template indicating which file the template comes from as well as the inheritances applied to it. **** JavaScript: assets.js (module @web/core/assets) takes care of loading libraries, javascripts and styles. `loadJS(url)` (loads the javascript and returns a resolved promise when the templates are also loaded via the '*.bundle.xml' service) `loadCSS(url)` (loads the style a resolved promise when the file is loaded) `loadXML(xml, app=assets.defaultApp)` (load template into application/owl, used by the `*.bundle.xml` services) `getBundle(bundleName)` (get the bundle descriptor) `loadBundle(desc)` (load the files and bundle from a descriptor) templates (XML element content all owl templates) A new `ready(serviceName)` method on boot.js lets you know when a service is loaded are the require. The xmlDependencies attribute no longer exists. Python: The xmls taken into account by assetbundle.py, applying `t-inherit` inheritances and adding an `name_of_the_bundle.bundle.xml` service in the generated JavaScript file. **** Every manifest changes is into the next commit, except 'web_tour' in this current commit as example. Part-of: odoo/odoo#95500 |