Skip to content

Commit

Permalink
[IMP] model: create snapshot when loading xlsx file
Browse files Browse the repository at this point in the history
Before this commit, when uploading an XLSX file, the code in the
Odoo repository would create a spreadsheet document with data that
is encoded in xml. Whenever the file is loaded, we parse the stringified
xml to convert it to the o-spreadsheet json structure. The problem is
that this conversion can be quite slow and costly when the XLSX file is
large.

This commit mitigates the issue by saving a snapshot once the XLSX file is
loaded for the first time.

closes #5445

Task: 4080514
X-original-commit: 4eb819f
Signed-off-by: Lucas Lefèvre (lul) <[email protected]>
Signed-off-by: Mehdi Rachico (mera) <[email protected]>
  • Loading branch information
Rachico committed Jan 9, 2025
1 parent dbe1304 commit 7b120ef
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,7 @@ export class Model extends EventBus<any> implements CommandDispatcher {

this.joinSession();

if (config.snapshotRequested) {
if (config.snapshotRequested || (data["[Content_Types].xml"] && !this.getters.isReadonly())) {
const startSnapshot = performance.now();
console.debug("Snapshot requested");
this.session.snapshot(this.exportData());
Expand Down
32 changes: 32 additions & 0 deletions tests/model/model.test.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
import { CommandResult, CorePlugin } from "../../src";
import { MESSAGE_VERSION } from "../../src/constants";
import { toZone } from "../../src/helpers";
import { Model, ModelConfig } from "../../src/model";
import { corePluginRegistry, featurePluginRegistry } from "../../src/plugins/index";
import { UIPlugin } from "../../src/plugins/ui_plugin";
import { Command, CommandTypes, CoreCommand, DispatchResult, coreTypes } from "../../src/types";
import { MockTransportService } from "../__mocks__/transport_service";
import { getTextXlsxFiles } from "../__xlsx__/read_demo_xlsx";
import { setupCollaborativeEnv } from "../collaborative/collaborative_helpers";
import { copy, selectCell, setCellContent } from "../test_helpers/commands_helpers";
import {
Expand Down Expand Up @@ -366,4 +369,33 @@ describe("Model", () => {
],
});
});

test("it should snapshot when importing xlsx file", async () => {
const transport = new MockTransportService();
const spy = jest.spyOn(transport, "sendMessage");
const xlsxData = await getTextXlsxFiles();
new Model(xlsxData, {
transportService: transport,
client: { id: "test", name: "Test" },
});
expect(spy).toHaveBeenCalledWith({
type: "SNAPSHOT",
version: MESSAGE_VERSION,
nextRevisionId: expect.any(String),
serverRevisionId: "START_REVISION",
data: expect.any(Object),
});
});

test("it should not snapshot when importing xlsx file in readonly mode", async () => {
const transport = new MockTransportService();
const spy = jest.spyOn(transport, "sendMessage");
const xlsxData = await getTextXlsxFiles();
new Model(xlsxData, {
transportService: transport,
client: { id: "test", name: "Test" },
mode: "readonly",
});
expect(spy).not.toHaveBeenCalled();
});
});

0 comments on commit 7b120ef

Please sign in to comment.