mirror of
https://github.com/gristlabs/grist-core.git
synced 2026-03-02 04:09:24 +00:00
(core) add explicit doc and inventory creation step
Summary: Currently, if a document is created by importing a file, inventory creation is a little haphazard - it works, but triggers a "surprise" message. This diff makes initialization of inventory explicit, so that surprise messages shouldn't happen during document creation. Test Plan: manual Reviewers: dsagal Reviewed By: dsagal Differential Revision: https://phab.getgrist.com/D2696
This commit is contained in:
@@ -110,6 +110,17 @@ export class DocSnapshotInventory implements IInventory {
|
||||
constructor(private _doc: ExternalStorage, private _meta: ExternalStorage,
|
||||
private _getFilename: (key: string) => Promise<string>) {}
|
||||
|
||||
/**
|
||||
* Start keeping inventory for a new document.
|
||||
*/
|
||||
public async create(key: string) {
|
||||
await this._mutex.runExclusive(key, async() => {
|
||||
const fname = await this._getFilename(key);
|
||||
await this._saveToFile(fname, []);
|
||||
this._needFlush.add(key);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a new snapshot of a document to the existing inventory. A prevSnapshotId may
|
||||
* be supplied as a cross-check. It will be matched against the most recent
|
||||
@@ -126,7 +137,7 @@ export class DocSnapshotInventory implements IInventory {
|
||||
await this._mutex.runExclusive(key, async() => {
|
||||
const snapshots = await this._getSnapshots(key, prevSnapshotId);
|
||||
// Could be already added if reconstruction happened.
|
||||
if (snapshots[0].snapshotId === snapshot.snapshotId) { return; }
|
||||
if (snapshots[0] && snapshots[0].snapshotId === snapshot.snapshotId) { return; }
|
||||
this._normalizeMetadata(snapshot);
|
||||
snapshots.unshift(snapshot);
|
||||
const fname = await this._getFilename(key);
|
||||
|
||||
Reference in New Issue
Block a user