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.

Task: 4080514
  • Loading branch information
Rachico committed Dec 20, 2024
1 parent a594943 commit 4804a36
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,10 @@ export class Model extends EventBus<any> implements CommandDispatcher {

this.joinSession();

if (config.snapshotRequested) {
if (
config.snapshotRequested ||
(data["[Content_Types].xml"] && this.config.mode !== "readonly")
) {
const startSnapshot = performance.now();
console.debug("Snapshot requested");
this.session.snapshot(this.exportData());
Expand Down
21 changes: 21 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,22 @@ describe("Model", () => {
],
});
});

test("snapshot when importing xlsx file", async () => {
jest.spyOn(console, "warn").mockImplementation(() => {});
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),
});
});
});

0 comments on commit 4804a36

Please sign in to comment.