Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Batch tracked users setup #40

Merged
merged 3 commits into from
Dec 4, 2023

Conversation

Half-Shot
Copy link
Member

The intention here is to handle things when thousands of requests are made to add tracked users and the async lock gets dogpiled. Async lock has a (sensible) limit of 1000 acquires before it gives up, so I think we should just queue up requests in a big batch and handle them like so.

Checklist

  • Tests written for all new code
  • Linter has been satisfied
  • Sign-off given on the changes (see CONTRIBUTING.md)

@Half-Shot Half-Shot requested a review from a team as a code owner November 24, 2023 18:16
Copy link
Member

@AndrewFerr AndrewFerr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good idea.
My only request is an optional one for performance reasons, but this looks functionally correct as it is.

return this.addTrackedUsersPromise = this.lock.acquire(SYNC_LOCK_NAME, async () => {
// Immediately clear this promise so that a new promise is queued up.
this.addTrackedUsersPromise = undefined;
const uids = [...this.trackedUsersToAdd].map(u => new UserId(u));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Might be worth avoiding creating an extra array with the spread syntax.

Something like this should work:

Suggested change
const uids = [...this.trackedUsersToAdd].map(u => new UserId(u));
const uids = Array<UserId>(this.trackedUsersToAdd.size);
let idx = 0;
for (const u of this.trackedUsersToAdd.values()) {
uids[idx++] = new UserId(u);
}

@AndrewFerr
Copy link
Member

Oh, and if you don't mind, rebase this directly onto upstream main before merging, since this could be PR'd into upstream too.

@Half-Shot Half-Shot merged commit a806668 into element-hq:main Dec 4, 2023
7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants