[FIX] website: invalidate snippet cache when switching website
Commit [1] keeps the snippet cache alive through different instance of the website snippet menu. This allows for the user to switch pages, even apps, while keeping the snippets in cache, decreasing the startup time of the snippet menu. However, the cache is not invalidated when switching website or installing a new theme. This commit adds a `invalidateSnippetCache` property to the websiteService. If this property is set to `true`, the cache will be invalidated next time the menus loads its snippet. This property is currently set to `true` when changing website and switching theme. [1]: https://github.com/odoo/odoo/commit/03c552690b15cbf2e7d6b7812386ac64042219af task-2687506 X-original-commit: bb503962a36f3798c50049f2844e7b288b632955 Part-of: odoo/odoo#102799
This commit is contained in:
committed by
Romain Derie
parent
24527568d1
commit
d7b2b7882f
@@ -22,6 +22,14 @@ export class WebsiteEditorComponent extends Component {
|
||||
});
|
||||
this.wysiwygOptions = {};
|
||||
|
||||
// TODO: This is done here because the snippet menu cannot access
|
||||
// OWL services. Once it can, the logic for invalidating the
|
||||
// cache should probably be moved there.
|
||||
if (this.websiteService.invalidateSnippetCache) {
|
||||
this.wysiwygOptions.invalidateSnippetCache = true;
|
||||
this.websiteService.invalidateSnippetCache = false;
|
||||
}
|
||||
|
||||
useChildSubEnv(legacyEnv);
|
||||
|
||||
onWillStart(async () => {
|
||||
|
||||
@@ -23,6 +23,7 @@ export function useLoaderOnClick() {
|
||||
async onClickViewButton(params) {
|
||||
const name = params.clickParams.name;
|
||||
if (['button_refresh_theme', 'button_choose_theme'].includes(name)) {
|
||||
website.invalidateSnippetCache = true;
|
||||
website.showLoader({ showTips: name !== 'button_refresh_theme' });
|
||||
try {
|
||||
const resParams = params.getResParams();
|
||||
|
||||
@@ -42,6 +42,8 @@ export const websiteService = {
|
||||
let blockingProcesses = [];
|
||||
let modelNamesProm = null;
|
||||
const modelNames = {};
|
||||
let invalidateSnippetCache = false;
|
||||
let lastWebsiteId = null;
|
||||
|
||||
const context = reactive({
|
||||
showNewContentModal: false,
|
||||
@@ -71,6 +73,10 @@ export const websiteService = {
|
||||
});
|
||||
return {
|
||||
set currentWebsiteId(id) {
|
||||
if (id && id !== lastWebsiteId) {
|
||||
invalidateSnippetCache = true;
|
||||
lastWebsiteId = id;
|
||||
}
|
||||
currentWebsiteId = id;
|
||||
websiteSystrayRegistry.trigger('EDIT-WEBSITE');
|
||||
},
|
||||
@@ -166,6 +172,13 @@ export const websiteService = {
|
||||
set actionJsId(jsId) {
|
||||
actionJsId = jsId;
|
||||
},
|
||||
get invalidateSnippetCache() {
|
||||
return invalidateSnippetCache;
|
||||
},
|
||||
set invalidateSnippetCache(value) {
|
||||
invalidateSnippetCache = value;
|
||||
},
|
||||
|
||||
goToWebsite({ websiteId, path, edition, translation } = {}) {
|
||||
action.doAction('website.website_preview', {
|
||||
clearBreadcrumbs: true,
|
||||
|
||||
@@ -0,0 +1,39 @@
|
||||
/** @odoo-module **/
|
||||
|
||||
import wTourUtils from 'website.tour_utils';
|
||||
|
||||
wTourUtils.registerWebsitePreviewTour('snippet_cache_across_websites', {
|
||||
edition: true,
|
||||
test: true,
|
||||
url: '/@/'
|
||||
}, [
|
||||
{
|
||||
content: "Check that the custom snippet is displayed",
|
||||
trigger: '#snippet_custom_body span:contains("custom_snippet_test")',
|
||||
run: () => null,
|
||||
},
|
||||
// There's no need to save, but canceling might or might not show a popup...
|
||||
...wTourUtils.clickOnSave(),
|
||||
{
|
||||
content: "Click on the website switch to switch to website 2",
|
||||
trigger: '.o_website_switcher_container button',
|
||||
},
|
||||
{
|
||||
content: "Switch to website 2",
|
||||
// Ensure data-website-id exists
|
||||
extra_trigger: 'iframe html[data-website-id="1"]',
|
||||
trigger: '.o_website_switcher_container .dropdown-item:nth-child(2)'
|
||||
},
|
||||
{
|
||||
content: "Wait for the iframe to be loaded",
|
||||
trigger: 'iframe html:not([data-website-id="1"])',
|
||||
run: () => null,
|
||||
},
|
||||
wTourUtils.clickOnEdit(),
|
||||
{
|
||||
content: "Check that the custom snippet is not here",
|
||||
extra_trigger: '#oe_snippets:not(:has(#snippet_custom_body span:contains("custom_snippet_test")))',
|
||||
trigger: '#oe_snippets:has(#snippet_custom.d-none)',
|
||||
run: () => null,
|
||||
},
|
||||
]);
|
||||
@@ -317,3 +317,17 @@ class TestUi(odoo.tests.HttpCase):
|
||||
|
||||
def test_23_website_multi_edition(self):
|
||||
self.start_tour('/@?enable_editor=1', 'website_multi_edition', login='admin')
|
||||
|
||||
def test_24_snippet_cache_across_websites(self):
|
||||
default_website = self.env.ref('website.default_website')
|
||||
self.env['ir.ui.view'].with_context(website_id=default_website.id).save_snippet(
|
||||
name='custom_snippet_test',
|
||||
arch="""
|
||||
<section class="s_text_block">
|
||||
<div class="custom_snippet_website_1">Custom Snippet Website 1</div>
|
||||
</section>
|
||||
""",
|
||||
thumbnail_url='/website/static/src/img/snippets_thumbs/s_text_block.svg',
|
||||
snippet_key='s_text_block',
|
||||
template_key='website.snippets')
|
||||
self.start_tour('/@/', 'snippet_cache_across_websites', login='admin')
|
||||
|
||||
Reference in New Issue
Block a user