[REF] spreadsheet_dashboard: use web_search_read to load dashboards
Previously, the dashboard action needed two RPC calls to be ready: 1. load the dashboard groups (with the dashboards ids in the groups) 2. load the dashboard display names Now, with the new `web_sear_read` we can load both at the same time, saving one http request. closes odoo/odoo#134984 Signed-off-by: Vincent Schippefilt (vsc) <vsc@odoo.com>
This commit is contained in:
+16
-23
@@ -30,7 +30,7 @@ export const Status = {
|
||||
* @typedef DashboardGroupData
|
||||
* @property {number} id
|
||||
* @property {string} name
|
||||
* @property {Array<number>} dashboardIds
|
||||
* @property {Array<{id: number, name: string}>} dashboards
|
||||
*
|
||||
* @typedef DashboardGroup
|
||||
* @property {number} id
|
||||
@@ -89,9 +89,9 @@ export class DashboardLoader {
|
||||
.map((group) => ({
|
||||
id: group.id,
|
||||
name: group.name,
|
||||
dashboardIds: group.dashboard_ids,
|
||||
dashboards: group.dashboard_ids,
|
||||
}));
|
||||
const dashboards = await this._fetchDashboardNames(this.groups);
|
||||
const dashboards = this.groups.map((group) => group.dashboards).flat();
|
||||
for (const dashboard of dashboards) {
|
||||
this.dashboards[dashboard.id] = {
|
||||
id: dashboard.id,
|
||||
@@ -120,10 +120,10 @@ export class DashboardLoader {
|
||||
return this.groups.map((section) => ({
|
||||
id: section.id,
|
||||
name: section.name,
|
||||
dashboards: section.dashboardIds.map((dashboardId) => ({
|
||||
id: dashboardId,
|
||||
displayName: this._getDashboard(dashboardId).displayName,
|
||||
status: this._getDashboard(dashboardId).status,
|
||||
dashboards: section.dashboards.map((dashboard) => ({
|
||||
id: dashboard.id,
|
||||
displayName: dashboard.name,
|
||||
status: this._getDashboard(dashboard.id).status,
|
||||
})),
|
||||
}));
|
||||
}
|
||||
@@ -132,25 +132,18 @@ export class DashboardLoader {
|
||||
* @private
|
||||
* @returns {Promise<{id: number, name: string, dashboard_ids: number[]}[]>}
|
||||
*/
|
||||
_fetchGroups() {
|
||||
return this.orm.searchRead(
|
||||
async _fetchGroups() {
|
||||
const groups = await this.orm.webSearchRead(
|
||||
"spreadsheet.dashboard.group",
|
||||
[["dashboard_ids", "!=", false]],
|
||||
["id", "name", "dashboard_ids"]
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @private
|
||||
* @param {Array<DashboardGroupData>} groups
|
||||
* @returns {Promise}
|
||||
*/
|
||||
_fetchDashboardNames(groups) {
|
||||
return this.orm.read(
|
||||
"spreadsheet.dashboard",
|
||||
groups.map((group) => group.dashboardIds).flat(),
|
||||
["name"]
|
||||
{
|
||||
specification: {
|
||||
name: {},
|
||||
dashboard_ids: { fields: { name: {} } },
|
||||
},
|
||||
}
|
||||
);
|
||||
return groups.records;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -80,8 +80,11 @@ QUnit.test("can switch spreadsheet", async (assert) => {
|
||||
QUnit.test("display no dashboard message", async (assert) => {
|
||||
await createSpreadsheetDashboard({
|
||||
mockRPC: function (route, { model, method, args }) {
|
||||
if (method === "search_read" && model === "spreadsheet.dashboard.group") {
|
||||
return [];
|
||||
if (method === "web_search_read" && model === "spreadsheet.dashboard.group") {
|
||||
return {
|
||||
records: [],
|
||||
length: 0,
|
||||
};
|
||||
}
|
||||
},
|
||||
});
|
||||
|
||||
@@ -98,7 +98,7 @@ QUnit.test("load spreadsheet data", async (assert) => {
|
||||
QUnit.test("load spreadsheet data only once", async (assert) => {
|
||||
const loader = await createDashboardLoader({
|
||||
mockRPC: function (route, args) {
|
||||
if (args.method === "read") {
|
||||
if (args.method === "read" && args.model === "spreadsheet.dashboard") {
|
||||
assert.step(`spreadsheet ${args.args[0]} loaded`);
|
||||
}
|
||||
},
|
||||
@@ -107,7 +107,7 @@ QUnit.test("load spreadsheet data only once", async (assert) => {
|
||||
let result = loader.getDashboard(3);
|
||||
await nextTick();
|
||||
assert.strictEqual(result.status, Status.Loaded);
|
||||
assert.verifySteps(["spreadsheet 1,2,3 loaded", "spreadsheet 3 loaded"]);
|
||||
assert.verifySteps(["spreadsheet 3 loaded"]);
|
||||
result = loader.getDashboard(3);
|
||||
await nextTick();
|
||||
assert.strictEqual(result.status, Status.Loaded);
|
||||
@@ -117,19 +117,22 @@ QUnit.test("load spreadsheet data only once", async (assert) => {
|
||||
QUnit.test("don't return empty dashboard group", async (assert) => {
|
||||
const loader = await createDashboardLoader({
|
||||
mockRPC: async function (route, args) {
|
||||
if (args.method === "search_read" && args.model === "spreadsheet.dashboard.group") {
|
||||
return [
|
||||
{
|
||||
id: 45,
|
||||
name: "Group A",
|
||||
dashboard_ids: [1],
|
||||
},
|
||||
{
|
||||
id: 46,
|
||||
name: "Group B",
|
||||
dashboard_ids: [],
|
||||
},
|
||||
];
|
||||
if (args.method === "web_search_read" && args.model === "spreadsheet.dashboard.group") {
|
||||
return {
|
||||
length: 2,
|
||||
records: [
|
||||
{
|
||||
id: 45,
|
||||
name: "Group A",
|
||||
dashboard_ids: [{ id: 1, name: "Dashboard CRM 1" }],
|
||||
},
|
||||
{
|
||||
id: 46,
|
||||
name: "Group B",
|
||||
dashboard_ids: [],
|
||||
},
|
||||
],
|
||||
};
|
||||
}
|
||||
},
|
||||
});
|
||||
@@ -152,13 +155,16 @@ QUnit.test("don't return empty dashboard group", async (assert) => {
|
||||
QUnit.test("load multiple spreadsheets", async (assert) => {
|
||||
const loader = await createDashboardLoader({
|
||||
mockRPC: function (route, args) {
|
||||
if (args.method === "read") {
|
||||
if (args.method === "web_search_read" && args.model === "spreadsheet.dashboard.group") {
|
||||
assert.step("load groups");
|
||||
}
|
||||
if (args.method === "read" && args.model === "spreadsheet.dashboard") {
|
||||
assert.step(`spreadsheet ${args.args[0]} loaded`);
|
||||
}
|
||||
},
|
||||
});
|
||||
await loader.load();
|
||||
assert.verifySteps(["spreadsheet 1,2,3 loaded"]);
|
||||
assert.verifySteps(["load groups"]);
|
||||
loader.getDashboard(1);
|
||||
await nextTick();
|
||||
assert.verifySteps(["spreadsheet 1 loaded"]);
|
||||
|
||||
Reference in New Issue
Block a user