mirror of
https://github.com/gristlabs/grist-core.git
synced 2026-03-02 04:09:24 +00:00
(core) Remove transform columns on shutdown
Summary: Call a new user action `RemoveTransformColumns` in ActiveDoc shutdown. Test Plan: Added nbrowser test Reviewers: georgegevoian, paulfitz Reviewed By: georgegevoian Differential Revision: https://phab.getgrist.com/D4107
This commit is contained in:
@@ -145,8 +145,22 @@ export interface TableRecordValue {
|
||||
|
||||
export type UserAction = Array<string|number|object|boolean|null|undefined>;
|
||||
|
||||
// Actions that trigger formula calculations in the data engine
|
||||
export const CALCULATING_USER_ACTIONS = new Set(['Calculate', 'UpdateCurrentTime', 'RespondToRequests']);
|
||||
// Actions that are performed automatically by the server
|
||||
// for things like regular maintenance or triggering formula calculations in the data engine.
|
||||
// Typically applied using `makeExceptionalDocSession("system")`.
|
||||
// They're also 'non-essential' in the sense that we don't need to worry about storing them
|
||||
// in action/undo history if they don't change anything (which they often won't)
|
||||
// and we can dismiss their result if the document is shutting down.
|
||||
export const SYSTEM_ACTIONS = new Set([
|
||||
// Initial dummy action performed when the document laods.
|
||||
'Calculate',
|
||||
// Called automatically at regular intervals, again to trigger formula calculations.
|
||||
'UpdateCurrentTime',
|
||||
// Part of the formula calculation process for formulas that use the `REQUEST` function.
|
||||
'RespondToRequests',
|
||||
// Performed at shutdown to clean up temporary helper columns.
|
||||
'RemoveTransformColumns'
|
||||
]);
|
||||
|
||||
export function getNumRows(action: DocAction): number {
|
||||
return !isDataAction(action) ? 0
|
||||
|
||||
@@ -1994,6 +1994,14 @@ export class ActiveDoc extends EventEmitter {
|
||||
// even if the doc is only ever opened briefly, without having to slow down startup.
|
||||
await safeCallAndWait("removeUnusedAttachments", () => this.removeUnusedAttachments(true, usageOptions));
|
||||
|
||||
if (this._dataEngine && this._fullyLoaded) {
|
||||
// Note that this must happen before `this._shuttingDown = true` because of this line in Sharing.ts:
|
||||
// if (this._activeDoc.isShuttingDown && isCalculate) {
|
||||
await safeCallAndWait("removeTransformColumns",
|
||||
() => this.applyUserActions(docSession, [["RemoveTransformColumns"]])
|
||||
);
|
||||
}
|
||||
|
||||
// Update data size; we'll be syncing both it and attachments size to the database soon.
|
||||
await safeCallAndWait("_updateDataSize", () => this._updateDataSize(usageOptions));
|
||||
}
|
||||
|
||||
@@ -8,7 +8,7 @@ import {
|
||||
UserActionBundle
|
||||
} from 'app/common/ActionBundle';
|
||||
import {ApplyUAExtendedOptions} from 'app/common/ActiveDocAPI';
|
||||
import {CALCULATING_USER_ACTIONS, DocAction, getNumRows, UserAction} from 'app/common/DocActions';
|
||||
import {DocAction, getNumRows, SYSTEM_ACTIONS, UserAction} from 'app/common/DocActions';
|
||||
import {allToken} from 'app/common/sharing';
|
||||
import {GranularAccessForBundle} from 'app/server/lib/GranularAccess';
|
||||
import log from 'app/server/lib/log';
|
||||
@@ -246,7 +246,7 @@ export class Sharing {
|
||||
|
||||
try {
|
||||
|
||||
const isCalculate = (userActions.length === 1 && CALCULATING_USER_ACTIONS.has(userActions[0][0] as string));
|
||||
const isCalculate = (userActions.length === 1 && SYSTEM_ACTIONS.has(userActions[0][0] as string));
|
||||
// `internal` is true if users shouldn't be able to undo the actions. Applies to:
|
||||
// - Calculate/UpdateCurrentTime because it's not considered as performed by a particular client.
|
||||
// - Adding attachment metadata when uploading attachments,
|
||||
|
||||
Reference in New Issue
Block a user