Skip to content

Commit

Permalink
Add upper bound when reading cached events by index
Browse files Browse the repository at this point in the history
  • Loading branch information
hpeebles committed Dec 28, 2023
1 parent 3baf35b commit eaf4d54
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion frontend/openchat-agent/src/utils/caching.ts
Original file line number Diff line number Diff line change
Expand Up @@ -383,8 +383,12 @@ export async function getCachedEventByIndex<T extends ChatEvent>(
const storeName =
context.threadRootMessageIndex === undefined ? "chat_events" : "thread_events";
const key = createCacheKey(context, eventIndex);
const upperBound = createCacheKey(context, MAX_INDEX);

const event = processEventExpiry(await db.get(storeName, IDBKeyRange.lowerBound(key)), now);
const event = processEventExpiry(
await db.get(storeName, IDBKeyRange.bound(key, upperBound)),
now,
);

if (
(event?.kind === "event" && event.index === eventIndex) ||
Expand Down

0 comments on commit eaf4d54

Please sign in to comment.