Skip to content

Commit

Permalink
[ECO-2257] Patch event store to not pull from local storage because i…
Browse files Browse the repository at this point in the history
…t's currently cached (#290)
  • Loading branch information
xbtmatt authored Oct 8, 2024
1 parent 0c7d105 commit 81a233e
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
7 changes: 2 additions & 5 deletions src/typescript/frontend/src/lib/store/event/event-store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import {
pushPeriodicStateEvents,
toMappedMarketEvents,
} from "./utils";
import { addToLocalStorage, initialStateFromLocalStorage } from "./local-storage";
import { initialStatePatch } from "./local-storage";
import { periodEnumToRawDuration } from "@sdk/const";
import { joinEmojis } from "@sdk/emoji_data";
import { createWebSocketClientStore, type WebSocketClientStore } from "../websocket/store";
Expand All @@ -28,7 +28,7 @@ import { DEBUG_ASSERT, extractFilter } from "@sdk/utils";
export const createEventStore = () => {
return createStore<EventStore & WebSocketClientStore>()(
immer((set, get) => ({
...initialStateFromLocalStorage(),
...initialStatePatch(),
getMarket: (m) => get().markets.get(joinEmojis(m)),
getRegisteredMarkets: () => {
return get().markets;
Expand All @@ -51,7 +51,6 @@ export const createEventStore = () => {
marketEvents.forEach((event) => market.stateEvents.push(event));
});
});
filtered.forEach(addToLocalStorage);
},
loadEventsFromServer: (eventsIn: Array<AnyEventModel>) => {
const guids = get().guids;
Expand All @@ -77,7 +76,6 @@ export const createEventStore = () => {
pushPeriodicStateEvents(market, extractFilter(marketEvents, isPeriodicStateEventModel));
DEBUG_ASSERT(() => marketEvents.length === 0);
});
events.forEach(addToLocalStorage);
});
},
pushEventFromClient: (event: AnyEventModel) => {
Expand Down Expand Up @@ -108,7 +106,6 @@ export const createEventStore = () => {
}
}
});
addToLocalStorage(event);
},
setLatestBars: ({ marketMetadata, latestBars }: SetLatestBarsArgs) => {
set((state) => {
Expand Down
10 changes: 10 additions & 0 deletions src/typescript/frontend/src/lib/store/event/local-storage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,16 @@ type MarketEventTypes =
| DatabaseModels["liquidity_events"]
| DatabaseModels["periodic_state_events"];

export const initialStatePatch = (): EventState => {
return {
guids: new Set<string>(),
stateFirehose: [],
marketRegistrations: [],
markets: new Map(),
globalStateEvents: [],
};
};

export const initialStateFromLocalStorage = (): EventState => {
// Purge stale events then load up the remaining ones.
const events = getEventsFromLocalStorage();
Expand Down

0 comments on commit 81a233e

Please sign in to comment.