Daily updates from Odoo
Wednesday, April 2, 2025
1 change · 18.0
Enhancements to existing features
Opening and navigating the Knowledge app is now significantly faster, especially when loading articles and the sidebar. The access-checking process was optimized to reuse existing permission data and avoid inefficient lookups, reducing wait times for users without changing who can access content.
Original PR description
Description ----------- The non-stored field `user_has_access` is the primary `ir.rule` used for a `knowledge.article` and is included in every query. As a result, the method…
Description
-----------
The non-stored field `user_has_access` is the primary `ir.rule` used for a `knowledge.article` and is included in every query. As a result, the method `_search_user_has_access` is frequently called and quickly becomes a performance bottleneck. This is particularly noticeable when opening the Knowledge app, as it involves reading the displayed article along with loading the sidebar.
This update optimizes the method as follows:
- For generic article access, the optimization leverages the field `inherited_permission`, which already contains the propagated `internal_permission` of the article along the hierarchy. This removes the need to recompute these permissions dynamically with a complex query since the data has already been precomputed.
- For member access, the query logic has been revised while maintaining the same outcome: Previously, the process involved: `for all articles, append the member and their permission, recurse into child articles for all in-sync and permissionless articles, and propagate the member's permission. Finally, discard all articles without any set permission.`, The new approach reverses the logic to avoid the need for discarding at the end and iterating through all articles: `for the articles the member belongs to, propagate the member's permission to its child articles, provided the child is in-sync, has no explicit permission, and the partner is not already a member of that article.` Although the last condition may seem counterintuitive, the initial set of articles considered encompasses those the member is linked to already. This also avoids cases where a parent article's member permission would overwrite differing permissions on its child articles.
- Additionally, `set` manipulations are used to handle IDs, thereby preventing the injection of large ID lists into multiple domain leaves. This improves query parsing and avoids poor query execution plans that could be caused by excessively large ID lists.
Benchmark
---------
On odoo.com, opening the Knowledge app from the Apps dashboard:
| Request | Before | After | Speed-up |
|----------------------|--------|-------|----------|
| web_read | 1.69s | 160ms | **10x** |
| get_sidebar_articles | 1.64s | 160ms | **10x** |
In a shell, searching articles with `[('user_has_access', '=', True)]`:
| User Type | Before | After | Speed-up |
|-----------------------|--------|-------|----------|
| `sudo` | 251ms | 35ms | **7x** |
| regular internal user | 577ms | 58ms | **10x** |
Reference
---------
task-4633813
Notice
------
⚠️ Note to clients/partners that might read this: For the full benefits of the patch, deploy the indexes that were added in this PR. This can be done by Upgrading the module `knowledge`, or creating the indexes manually in database. The patch should still be a net-benefit even for database without the indexes deployed.