Skip to content

Commit

Permalink
Limit updates returned from getUpdates to 100
Browse files Browse the repository at this point in the history
  • Loading branch information
rojvv committed Apr 11, 2024
1 parent bd1237d commit ae118d5
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
2 changes: 1 addition & 1 deletion client/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ Deno Deploy, Cloudflare Workers, and more.

### `connect()` and `authorize()`

The [`Client`] class of this module does not have these methods, since it is
The `Client` class of this module does not have these methods, since it is
neither required to make a connection initially, nor to authorize.

### Telegram API Calls
Expand Down
11 changes: 9 additions & 2 deletions client_manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,7 @@ export class ClientManager {
}

#polls = new Set<Client>();
static #GET_UPDATES_MAX_UPDATES = 100;
#updateResolvers = new Map<Client, () => void>();
#getUpdatesControllers = new Map<Client, AbortController>();
async #getUpdatesInner(id: string, timeoutSeconds: number) {
Expand All @@ -235,7 +236,10 @@ export class ClientManager {
try {
let updates = this.#updates.get(client);
if (updates && updates.length) {
return updates.splice(0, updates.length);
return updates.splice(
0,
Math.min(ClientManager.#GET_UPDATES_MAX_UPDATES, updates.length),
);
}

controller = new AbortController();
Expand All @@ -253,7 +257,10 @@ export class ClientManager {

updates = this.#updates.get(client);
if (updates && updates.length) {
return updates.splice(0, updates.length);
return updates.splice(
0,
Math.min(ClientManager.#GET_UPDATES_MAX_UPDATES, updates.length),
);
} else {
return [];
}
Expand Down

0 comments on commit ae118d5

Please sign in to comment.