[FIX] base,bus: Notify bundle change on version change
Before this commit: a notification asking to reload the current window appeared as soon as the server detected a change in one of the assets bundles, even on first load. To fix this problem and make the feature more meaningful, it has been decided to only notify the client when the server version (not the bundle version) is outdated (i.e. on database upgrades, when the changes in the code are actually relevant). closes odoo/odoo#82032 X-original-commit: a3b5a9d715be6a93c7f2859074b916f3249f97c3 Signed-off-by: Antony Lesuisse <al@odoo.com> Signed-off-by: Julien Mougenot (jum) <jum@odoo.com>
This commit is contained in:
@@ -2,24 +2,17 @@
|
||||
|
||||
import { browser } from "@web/core/browser/browser";
|
||||
import { registry } from "@web/core/registry";
|
||||
import { session } from "@web/session";
|
||||
|
||||
export const assetsWatchdogService = {
|
||||
dependencies: ["notification"],
|
||||
|
||||
start(env, { notification }) {
|
||||
const assets = {};
|
||||
let isNotificationDisplayed = false;
|
||||
let bundleNotifTimerID = null;
|
||||
|
||||
env.bus.on("WEB_CLIENT_READY", null, async () => {
|
||||
const legacyEnv = owl.Component.env;
|
||||
|
||||
document.querySelectorAll("*[data-asset-bundle]").forEach((el) => {
|
||||
assets[el.getAttribute("data-asset-bundle")] = el.getAttribute(
|
||||
"data-asset-version"
|
||||
);
|
||||
});
|
||||
|
||||
legacyEnv.services.bus_service.onNotification(this, onNotification);
|
||||
legacyEnv.services.bus_service.startPolling();
|
||||
});
|
||||
@@ -78,7 +71,7 @@ export const assetsWatchdogService = {
|
||||
function onNotification(notifications) {
|
||||
for (const { payload, type } of notifications) {
|
||||
if (type === 'bundle_changed') {
|
||||
if (payload.name in assets && payload.version !== assets[payload.name]) {
|
||||
if (payload.server_version !== session.server_version) {
|
||||
displayBundleChangedNotification();
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -48,10 +48,7 @@ QUnit.module("Bus Assets WatchDog", (hooks) => {
|
||||
return [{
|
||||
message: {
|
||||
type: 'bundle_changed',
|
||||
payload: {
|
||||
name: 'web.assets_backend',
|
||||
version: 'newHash',
|
||||
},
|
||||
payload: { server_version: "NEW_MAJOR_VERSION" },
|
||||
},
|
||||
}];
|
||||
}
|
||||
|
||||
@@ -47,6 +47,5 @@ class BusWebTests(odoo.tests.HttpCase):
|
||||
)
|
||||
for (channel, message) in sendones:
|
||||
self.assertEqual(channel, 'broadcast')
|
||||
self.assertEqual(len(message), 2)
|
||||
self.assertIn(message.get('name'), bundle_xml_ids)
|
||||
self.assertTrue(isinstance(message.get('name'), str))
|
||||
self.assertEqual(len(message), 1)
|
||||
self.assertTrue(isinstance(message.get('server_version'), str))
|
||||
|
||||
@@ -26,6 +26,7 @@ from odoo.modules.module import get_resource_path
|
||||
from odoo.tools import func, misc, transpile_javascript, is_odoo_module, SourceMapGenerator, profiler
|
||||
from odoo.tools.misc import file_open, html_escape as escape
|
||||
from odoo.tools.pycompat import to_text
|
||||
from odoo.release import version as server_version
|
||||
|
||||
_logger = logging.getLogger(__name__)
|
||||
|
||||
@@ -343,8 +344,7 @@ class AssetsBundle(object):
|
||||
# to invite the user to refresh their browser
|
||||
if self.env and 'bus.bus' in self.env and self.name in self.TRACKED_BUNDLES:
|
||||
self.env['bus.bus']._sendone('broadcast', 'bundle_changed', {
|
||||
'name': self.name,
|
||||
'version': self.version,
|
||||
'server_version': server_version
|
||||
})
|
||||
_logger.debug('Asset Changed: bundle: %s -- version: %s', self.name, self.version)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user