mirror of
https://github.com/gristlabs/grist-core.git
synced 2026-03-02 04:09:24 +00:00
(core) do not look at content of recent actions when loading documents
Summary: This removes the need for any information drawn from the content of recent actions when loading a document. The undo/redo system does need some facts about recent actions up front. But that system has an important restriction: only actions a particular client is known to have generated can be undone by that client. So in this diff, as we store which client has performed an action, we also store the few pieces of metadata about that action that the undo/redo system needs: `linkId`, `otherId`, `rowIdHint`, `isUndo` fields. These are all small integers (or in one case a boolean). An existing limitation is that information about which client has performed which action is stored in memory in the worker, and not persisted anywhere. This diff does not change that limitation, meaning that undos continue to not survive a worker transition. A reasonable way to deal with that would be to back the store with redis. Test Plan: existing tests pass Reviewers: dsagal Reviewed By: dsagal Differential Revision: https://phab.getgrist.com/D3044
This commit is contained in:
@@ -44,7 +44,7 @@ import {startWelcomeTour} from 'app/client/ui/welcomeTour';
|
||||
import {isNarrowScreen, mediaSmall, testId} from 'app/client/ui2018/cssVars';
|
||||
import {IconName} from 'app/client/ui2018/IconList';
|
||||
import {FieldEditor} from "app/client/widgets/FieldEditor";
|
||||
import {ActionGroup} from 'app/common/ActionGroup';
|
||||
import {MinimalActionGroup} from 'app/common/ActionGroup';
|
||||
import {ClientQuery} from "app/common/ActiveDocAPI";
|
||||
import {delay} from 'app/common/delay';
|
||||
import {DisposableWithEvents} from 'app/common/DisposableWithEvents';
|
||||
@@ -376,7 +376,7 @@ export class GristDoc extends DisposableWithEvents {
|
||||
* Switch to the view/section and scroll to the record indicated by cursorPos. If cursorPos is
|
||||
* null, then moves to a position best suited for optActionGroup (not yet implemented).
|
||||
*/
|
||||
public async moveToCursorPos(cursorPos?: CursorPos, optActionGroup?: ActionGroup): Promise<void> {
|
||||
public async moveToCursorPos(cursorPos?: CursorPos, optActionGroup?: MinimalActionGroup): Promise<void> {
|
||||
if (!cursorPos || cursorPos.sectionId == null) {
|
||||
// TODO We could come up with a suitable cursorPos here based on the action itself.
|
||||
// This should only come up if trying to undo/redo after reloading a page (since the cursorPos
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
import {CursorPos} from 'app/client/components/Cursor';
|
||||
import {GristDoc} from 'app/client/components/GristDoc';
|
||||
import * as dispose from 'app/client/lib/dispose';
|
||||
import {ActionGroup} from 'app/common/ActionGroup';
|
||||
import {MinimalActionGroup} from 'app/common/ActionGroup';
|
||||
import {PromiseChain} from 'app/common/gutil';
|
||||
import {fromKo, Observable} from 'grainjs';
|
||||
import * as ko from 'knockout';
|
||||
|
||||
export interface ActionGroupWithCursorPos extends ActionGroup {
|
||||
export interface ActionGroupWithCursorPos extends MinimalActionGroup {
|
||||
cursorPos?: CursorPos;
|
||||
}
|
||||
|
||||
@@ -27,13 +27,13 @@ export class UndoStack extends dispose.Disposable {
|
||||
private _gristDoc: GristDoc;
|
||||
private _stack: ActionGroupWithCursorPos[];
|
||||
private _pointer: number;
|
||||
private _linkMap: {[actionNum: number]: ActionGroup};
|
||||
private _linkMap: {[actionNum: number]: MinimalActionGroup};
|
||||
|
||||
// Chain of promises which send undo actions to the server. This delays the execution of the
|
||||
// next action until the current one has been received and moved the pointer index.
|
||||
private _undoChain = new PromiseChain<void>();
|
||||
|
||||
public create(log: ActionGroup[], options: {gristDoc: GristDoc}) {
|
||||
public create(log: MinimalActionGroup[], options: {gristDoc: GristDoc}) {
|
||||
this._gristDoc = options.gristDoc;
|
||||
|
||||
// TODO: _stack and _linkMap grow without bound within a single session.
|
||||
@@ -65,7 +65,7 @@ export class UndoStack extends dispose.Disposable {
|
||||
* Should only be given own actions. Pays attention to actionNum, otherId, linkId, and
|
||||
* uses those to adjust undo index.
|
||||
*/
|
||||
public pushAction(ag: ActionGroup): void {
|
||||
public pushAction(ag: MinimalActionGroup): void {
|
||||
if (!ag.fromSelf) {
|
||||
return;
|
||||
}
|
||||
@@ -133,7 +133,7 @@ export class UndoStack extends dispose.Disposable {
|
||||
/**
|
||||
* Find all actionGroups in the bundle that starts with the given action group.
|
||||
*/
|
||||
private _findActionBundle(ag: ActionGroup) {
|
||||
private _findActionBundle(ag: MinimalActionGroup) {
|
||||
const prevNums = new Set();
|
||||
const actionGroups = [];
|
||||
// Follow references through the linkMap adding items to the array bundle.
|
||||
|
||||
Reference in New Issue
Block a user