Skip to content

Commit 3bcdc12

Browse files
committed
core: enforce filter.limit in getMessageStream if type is undefined
1 parent db7b8c7 commit 3bcdc12

File tree

1 file changed

+19
-3
lines changed
  • packages/core/src/components/messageStore/node

1 file changed

+19
-3
lines changed

packages/core/src/components/messageStore/node/index.ts

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -323,9 +323,25 @@ class SqliteMessageStore implements MessageStore {
323323
): AsyncIterable<[Uint8Array, Message]> {
324324
const { type, limit, app } = filter
325325
if (type === undefined) {
326-
yield* this.getSessionStream({ limit, app })
327-
yield* this.getActionStream({ limit, app })
328-
yield* this.getCustomActionStream({ limit, app })
326+
const countMax = limit ?? Infinity
327+
let count = 0
328+
for await (const session of this.getSessionStream({ limit, app })) {
329+
if (count++ < countMax) {
330+
yield session
331+
}
332+
}
333+
334+
for await (const session of this.getActionStream({ limit, app })) {
335+
if (count++ < countMax) {
336+
yield session
337+
}
338+
}
339+
340+
for await (const session of this.getCustomActionStream({ limit, app })) {
341+
if (count++ < countMax) {
342+
yield session
343+
}
344+
}
329345
} else if (type === "session") {
330346
yield* this.getSessionStream({ limit, app })
331347
} else if (type === "action") {

0 commit comments

Comments
 (0)