From 74693e3291fdb49aa2ce94fd323e86a17c977509 Mon Sep 17 00:00:00 2001 From: Juha Paananen Date: Fri, 2 Feb 2024 19:39:37 +0200 Subject: [PATCH] Remove history tracking on client This was not utilized anymore, since the history view feature was removed long time ago. --- common/src/board-history-reducer.ts | 3 +-- frontend/src/board/BoardView.tsx | 1 - frontend/src/board/ItemView.tsx | 4 ---- frontend/src/store/board-local-store.ts | 2 -- frontend/src/store/board-store.test.ts | 2 -- frontend/src/store/board-store.ts | 30 +++++++++---------------- 6 files changed, 11 insertions(+), 31 deletions(-) diff --git a/common/src/board-history-reducer.ts b/common/src/board-history-reducer.ts index 364418b7d..a2d7eea50 100644 --- a/common/src/board-history-reducer.ts +++ b/common/src/board-history-reducer.ts @@ -14,8 +14,7 @@ export function boardHistoryReducer( appEvent: BoardHistoryEntry, ): [BoardWithHistory, PersistableBoardItemEvent | null] { const [updatedBoard, undoAction] = boardReducer(board.board, appEvent) - const history = updatedBoard !== board.board ? addToHistory(board.history, appEvent) : board.history - const updatedBoardWithHistory = { board: updatedBoard, history } + return [updatedBoardWithHistory, undoAction ? undoAction() : null] } diff --git a/frontend/src/board/BoardView.tsx b/frontend/src/board/BoardView.tsx index 1bb243e1a..5b16b88a6 100644 --- a/frontend/src/board/BoardView.tsx +++ b/frontend/src/board/BoardView.tsx @@ -83,7 +83,6 @@ export const BoardView = ({ L.filter((b: Board) => !!b, componentScope()), ) const accessLevel = L.view(boardState, "accessLevel") - const history = L.view(boardState, "serverHistory") const locks = L.view(boardState, (s) => s.locks) const sessionId = L.view(sessionState, (s) => s.sessionId) const sessions = L.view(boardState, (s) => s.users) diff --git a/frontend/src/board/ItemView.tsx b/frontend/src/board/ItemView.tsx index a534114cc..539e7a6e8 100644 --- a/frontend/src/board/ItemView.tsx +++ b/frontend/src/board/ItemView.tsx @@ -3,16 +3,13 @@ import * as L from "lonna" import { AccessLevel, Board, - BoardHistoryEntry, canWrite, Connection, getAlign, getHorizontalAlign, getItemBackground, - getItemIds, getItemShape, getVerticalAlign, - Id, isTextItem, Item, ItemType, @@ -46,7 +43,6 @@ export const ItemView = ({ }: { board: L.Property accessLevel: L.Property - history: L.Property id: string type: ItemType item: L.Property diff --git a/frontend/src/store/board-local-store.ts b/frontend/src/store/board-local-store.ts index 18e34e8b6..c5562df18 100644 --- a/frontend/src/store/board-local-store.ts +++ b/frontend/src/store/board-local-store.ts @@ -6,7 +6,6 @@ import { migrateBoard, migrateEvent } from "../../../common/src/migration" export type LocalStorageBoard = { serverShadow: Board queue: BoardHistoryEntry[] // serverShadow + queue = current board - serverHistory: BoardHistoryEntry[] // history until serverShadow (queued events not included) } const BOARD_STORAGE_KEY_PREFIX = "board_" @@ -31,7 +30,6 @@ async function getStoredState(localStorageKey: string): Promise { locallyStoredBoard: { serverShadow: board1, queue: [], - serverHistory: [], }, }) @@ -137,7 +136,6 @@ describe("With stored local state", () => { locallyStoredBoard: { serverShadow: board1, queue: [], - serverHistory: [], }, }) diff --git a/frontend/src/store/board-store.ts b/frontend/src/store/board-store.ts index 278257d1b..909666a69 100644 --- a/frontend/src/store/board-store.ts +++ b/frontend/src/store/board-store.ts @@ -2,7 +2,6 @@ import _ from "lodash" import * as L from "lonna" import { globalScope } from "lonna" import { addOrReplaceEvent, foldActions } from "../../../common/src/action-folding" -import { boardHistoryReducer } from "../../../common/src/board-history-reducer" import { boardReducer } from "../../../common/src/board-reducer" import { AccessLevel, @@ -54,7 +53,6 @@ export type BoardState = { board: Board | undefined serverShadow: Board | undefined queue: (BoardHistoryEntry | CursorMove)[] // serverShadow + queue = current board - serverHistory: BoardHistoryEntry[] // history until serverShadow (queued events not included) sent: (BoardHistoryEntry | CursorMove)[] locks: ItemLocks users: UserSessionInfo[] @@ -168,7 +166,7 @@ export function BoardStore( let redoStack = CommandStack() let initialServerSyncEventBuffer: BoardHistoryEntry[] = [] - + let eventsSinceInit = 0 const eventsReducer = (state: BoardState, event: BoardStoreEvent): BoardState => { const storedInitialState = boardStateFromLocalStorage.get()?.storedInitialState @@ -181,6 +179,10 @@ export function BoardStore( } else if (event.action === "ui.redo") { return redoStack.pop(state, undoStack) } else if (isPersistableBoardItemEvent(event)) { + if (eventsSinceInit == 0) { + console.log("First event since init at serial", event.serial) + } + eventsSinceInit++ try { if (event.serial == undefined) { if (!canWrite(state.accessLevel)) return state @@ -191,10 +193,7 @@ export function BoardStore( return flushIfPossible({ ...state, board, queue: addOrReplaceEvent(event, state.queue) }) } else { // Remote event - const [{ board: newServerShadow, history: newServerHistory }] = boardHistoryReducer( - { board: state.serverShadow!, history: state.serverHistory }, - event, - ) + const [newServerShadow] = boardReducer(state.serverShadow!, event) // Rebase local events on top of new server shadow // TODO: what if fails? const localEvents = [...state.sent, ...state.queue] @@ -202,7 +201,7 @@ export function BoardStore( .filter(isBoardHistoryEntry) .reduce((b, e) => boardReducer(b, e)[0], newServerShadow) //console.log(`Processed remote board event and rebased ${localEvents.length} local events on top`, event) - return { ...state, serverShadow: newServerShadow, board, serverHistory: newServerHistory } + return { ...state, serverShadow: newServerShadow, board } } } catch (e) { console.error("Error applying event. Fetching as new board...", e) @@ -224,9 +223,8 @@ export function BoardStore( //console.log("Got ack") return flushIfPossible({ ...state, sent: [] }) } else { - // Our sent events now acknowledged and will be incorporated into serverShadow and serverHistory + // Our sent events now acknowledged and will be incorporated into serverShadow const newServerEvents = state.sent.filter(isBoardHistoryEntry) - const newServerHistory = [...state.serverHistory, ...newServerEvents] const newServerShadow = state.queue.length > 0 ? newServerEvents.reduce((b, e) => boardReducer(b, e)[0], state.serverShadow!) @@ -238,7 +236,6 @@ export function BoardStore( ...state, board: { ...state.board!, serial: newSerial }, serverShadow: { ...newServerShadow, serial: newSerial }, - serverHistory: newServerHistory, sent: [], }) } @@ -307,7 +304,6 @@ export function BoardStore( status: "offline", queue: storedInitialState.queue, sent: [], - serverHistory: storedInitialState.serverHistory, serverShadow: storedInitialState.serverShadow, board, } @@ -341,6 +337,7 @@ export function BoardStore( const users = state.users.map((u) => (u.sessionId === event.sessionId ? event : u)) return { ...state, users } } else if (event.action === "board.init") { + eventsSinceInit = 0 console.log(`Going to online mode. Init as new board at serial ${event.board.serial}`) return { ...state, @@ -349,12 +346,9 @@ export function BoardStore( accessLevel: event.accessLevel, serverShadow: event.board, sent: [], - serverHistory: [ - // Create a bootstrap event to make the local history consistent even though we don't have the full history from server. - mkBootStrapEvent(event.board.id, event.board, event.board.serial), - ], } } else if (event.action === "board.init.diff") { + eventsSinceInit = 0 if (event.first) { // Ensure local buffer empty on first chunk even if an earlier init was aborted. initialServerSyncEventBuffer = [] @@ -413,7 +407,6 @@ export function BoardStore( ) // Local board = server shadow + local queue const board = queue.reduce((b, e) => boardReducer(b, e)[0], newServerShadow) - const newServerHistory = [...state.serverHistory, ...initialServerSyncEventBuffer] initialServerSyncEventBuffer = [] @@ -424,7 +417,6 @@ export function BoardStore( board, serverShadow: newServerShadow, queue, - serverHistory: newServerHistory, }) } catch (e) { console.error("Error initializing board. Fetching as new board...", e) @@ -454,7 +446,6 @@ export function BoardStore( accessLevel: "none", serverShadow: undefined, board: undefined, - serverHistory: [], locks: {}, users: [], queue: [], @@ -481,7 +472,6 @@ export function BoardStore( L.map((state) => { return { serverShadow: state.serverShadow!, - serverHistory: state.serverHistory, queue: state.queue.filter(isBoardHistoryEntry), } }),