[IMP] website_event: improve web tracking

In 2 ways:
- by ignoring prefetched pages: indeed some page were reported inaccurately
as being viewed by the user when they were only prefetched.
- by adding the page /event in the tracked page as the page is obviously
important in the event business

Technical notes:
- The prefetched pages are ignored thanks to an header X-Disable-Tracking added
on each prefetch request in the service worker.
- Adding the page /event as a tracked page has increased the number of queries
when browsing the page /event. That's why some query count have been updated in
TestOnlineEventPerformance.

Task-2476513

Part-of: odoo/odoo#86031
This commit is contained in:
Pierre-Yves Dufays
2022-04-29 08:09:58 +02:00
parent aef2d27053
commit 80115e8dd3
3 changed files with 14 additions and 8 deletions
@@ -444,7 +444,7 @@ class TestOnlineEventPerformance(EventPerformanceCase, UtilPerf):
# website customer data
with freeze_time(self.reference_now):
self.authenticate('user_eventmanager', 'user_eventmanager')
with self.assertQueryCount(default=50): # tef only: 49
with self.assertQueryCount(default=60): # com runbot: 59 - ent runbot:60
self._test_url_open('/event')
@warmup
@@ -452,7 +452,7 @@ class TestOnlineEventPerformance(EventPerformanceCase, UtilPerf):
# website customer data
with freeze_time(self.reference_now):
self.authenticate(None, None)
with self.assertQueryCount(default=30):
with self.assertQueryCount(default=39): # com runbot: 39 - ent runbot: 39
self._test_url_open('/event')
# @warmup
@@ -2,7 +2,7 @@
<odoo>
<!-- Index -->
<template id="index" name="Events">
<template id="index" name="Events" track="1">
<t t-call="website.layout">
<div id="wrap" class="o_wevent_index">
<!-- Options -->
@@ -236,14 +236,20 @@ const matchCache = async (request) => {
/**
*
* @param {FetchEvent} param0
* @param {Request} request
* @param {object} [options]
* @param {Boolean} [options.disableTracking] whether adding a header preventing the server to track the request
* @returns {Promise<Response>}
*/
const processFetchRequest = async ({ request }) => {
const processFetchRequest = async (request, options) => {
const requestCopy = request.clone();
let response;
try {
response = await fetch(request);
if (options && options.disableTracking) {
response = await fetch(request, { headers: { 'X-Disable-Tracking': '1' } });
} else {
response = await fetch(request);
}
await cacheRequest(request, response);
} catch (requestError) {
if (isCachableRequest(requestCopy)) {
@@ -308,7 +314,7 @@ const prefetchUrls = async (urls = []) => {
continue;
}
try {
await processFetchRequest({ request: new Request(url) });
await processFetchRequest(new Request(url), { disableTracking: true });
} catch (error) {
console.error(`fail to prefetch ${url} : ${error}`);
}
@@ -347,7 +353,7 @@ const processMessage = (data) => {
};
self.addEventListener("fetch", (event) => {
event.respondWith(processFetchRequest(event));
event.respondWith(processFetchRequest(event.request));
});
self.addEventListener("sync", (event) => {