Skip to content

Commit

Permalink
fix: avoid querying threads with 0 limit (#1361)
Browse files Browse the repository at this point in the history
  • Loading branch information
isekovanic committed Sep 11, 2024
1 parent 34bc8d7 commit 1393bac
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/thread_manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,9 @@ export class ThreadManager<SCG extends ExtendableGenerics = DefaultGenerics> {
},
}));

const response = await this.queryThreads({ limit: Math.min(limit, MAX_QUERY_THREADS_LIMIT) });
const response = await this.queryThreads({
limit: Math.min(limit, MAX_QUERY_THREADS_LIMIT) || MAX_QUERY_THREADS_LIMIT,
});

const currentThreads = this.threadsById;
const nextThreads: Thread<SCG>[] = [];
Expand Down
8 changes: 8 additions & 0 deletions test/unit/threads.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1099,6 +1099,14 @@ describe('Threads 2.0', () => {
});

describe('reload', () => {
it('reloads with a default limit if both threads and unseenThreadIds are empty', async () => {
threadManager.state.partialNext({
threads: [],
unseenThreadIds: [],
});
await threadManager.reload();
expect(stubbedQueryThreads.calledWithMatch({ limit: 25 })).to.be.true;
});
it('skips reload if there were no updates since the latest reload', async () => {
threadManager.state.partialNext({ ready: true });
await threadManager.reload();
Expand Down

0 comments on commit 1393bac

Please sign in to comment.