mirror of
https://github.com/gristlabs/grist-core.git
synced 2026-03-02 04:09:24 +00:00
(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:
@@ -1,7 +1,8 @@
|
||||
import {Features} from 'app/common/Features';
|
||||
import {nativeValues} from 'app/gen-server/lib/values';
|
||||
import * as assert from 'assert';
|
||||
import {BaseEntity, Column, Connection, Entity, PrimaryGeneratedColumn} from 'typeorm';
|
||||
import {BillingAccount} from 'app/gen-server/entity/BillingAccount';
|
||||
import {BaseEntity, Column, Connection, Entity, OneToMany, PrimaryGeneratedColumn} from 'typeorm';
|
||||
|
||||
/**
|
||||
* A summary of features used in 'starter' plans.
|
||||
@@ -149,6 +150,9 @@ export class Product extends BaseEntity {
|
||||
|
||||
@Column({type: nativeValues.jsonEntityType})
|
||||
public features: Features;
|
||||
|
||||
@OneToMany(type => BillingAccount, account => account.product)
|
||||
public accounts: BillingAccount[];
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -2325,6 +2325,18 @@ export class HomeDBManager extends EventEmitter {
|
||||
});
|
||||
}
|
||||
|
||||
public async getDocProduct(docId: string): Promise<Product | undefined> {
|
||||
return await this._connection.createQueryBuilder()
|
||||
.select('product')
|
||||
.from(Product, 'product')
|
||||
.leftJoinAndSelect('product.accounts', 'account')
|
||||
.leftJoinAndSelect('account.orgs', 'org')
|
||||
.leftJoinAndSelect('org.workspaces', 'workspace')
|
||||
.leftJoinAndSelect('workspace.docs', 'doc')
|
||||
.where('doc.id = :docId', {docId})
|
||||
.getOne();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the anonymous user, as a constructed object rather than a database lookup.
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user