(core) Prune snapshots outside the window in product features

Summary:
- Add a method `getSnapshotWindow` to `IInventory` and `DocSnapshotInventory`. It returns a `SnapshotWindow`, which represents a duration of time for which we keep backups for a particular document.
- `DocSnapshotPruner` calls this method and passes the window to `shouldKeepSnapshots` to determine which document versions have fallen outside the window and should be pruned.
- The implementation passed to `DocSnapshotInventory` uses a new method `getDocProduct` in `HomeDBManager` which directly returns the `Product` associated with a document, given only the document ID. Other methods in `HomeDBManager` require passing more information, especially about a user, but `DocSnapshotPruner` only knows about document IDs.

Test Plan: Added a test for `getDocProduct` and a test for `DocSnapshotPruner` where `getSnapshotWindow` is specified.

Reviewers: paulfitz

Reviewed By: paulfitz

Differential Revision: https://phab.getgrist.com/D3322
This commit is contained in:
Alex Hall
2022-03-15 12:45:20 +02:00
parent 21f1dfa56c
commit ec8460b772
5 changed files with 64 additions and 21 deletions

View File

@@ -1,3 +1,8 @@
export interface SnapshotWindow {
count: number;
unit: 'month' | 'year';
}
// A product is essentially a list of flags and limits that we may enforce/support.
export interface Features {
vanityDomain?: boolean; // are user-selected domains allowed (unenforced) (default: true)
@@ -35,10 +40,7 @@ export interface Features {
readOnlyDocs?: boolean; // if set, docs can only be read, not written.
snapshotWindow?: { // if set, controls how far back snapshots are kept.
count: number; // TODO: not honored at time of writing.
unit: 'month'|'year';
};
snapshotWindow?: SnapshotWindow; // if set, controls how far back snapshots are kept.
baseMaxRowsPerDocument?: number; // If set, establishes a default maximum on the
// number of rows (total) in a single document.