Files
odoo_source/addons/website/tests
Xavier-Do 76adca8ec9 [FIX] website: clear cache on ir.asset archive
Since #121376 a clear_cache was removed when unlinking an attachment

This clear_cache was not useful when restarting a server with new
sources, an other operation changing the content of an assets should
invalidate the cache manually. This is the case of ir.asset CUD
operations.

Unfortunately, a manual update was left missing in website, when
archiving ir.assets used for snippets.

This was discovered on runbot, with two workers, when the first workers
generates assets before the cron, and the second one after the cron.

The second worker unlinks attachments creating an inconsistency in the
cache of the first one.

This problem can be solved quickly by invalidating the assets cache in
the cron manually but this will be done in all cases. The proposed
solution will check the ir.asset that should change and only clear the
cache if the state changed.

Regarding performances, this should actually be a slight improvement in
query count since at the cost of one more select to prefetch the record
we can avoid multiple update, one per snippet. In most case no update at
all should be done, at most 2 can be done (one for archive, one for
unarchive).

Example with some assets to unarchive:

Before:
TOTAL ENTRIES: 277
SELECT: 158 (~0.16591858863830566s)
UNKWOW: 54 (~0.0202481746673584s)
UPDATE: 65 (~0.03202557563781738s)

After:
TOTAL ENTRIES: 214
SELECT: 159 (~0.1663439826965332s)
UNKWOW: 54 (~0.029229164123535156s)
UPDATE: 1 (~0.0002865791320800781s)

If the number of query is lowered, the python processing is slightly
higher. Locally the test time is similar, slightly longer since an
additional call to _disable_unused_snippets_assets was added to check
the cache invalidation

closes odoo/odoo#130973

X-original-commit: 3aeab51ff4379e6d76172614fd39f09d6c449ac6
Signed-off-by: Xavier Dollé (xdo) <xdo@odoo.com>
2023-08-06 17:58:53 +02:00
..