CenterForDigitalHumanities / CenterForDigitalHumanities/TPEN-services

Background User merging

Open
#484 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
JavaScript
Stars
2
Forks
0
PR merge metrics
No merged PRs in 30d

Description

Copilot is concerned we'll get too many users at once and block ourselves.

> The authentication middleware now handles temporary user merging, which could be a slow operation involving multiple database queries and group updates. This blocking operation happens on every authenticated request for new users. Consider offloading this to a background job or showing a loading state to the user, as this could cause request timeouts for users with many project invitations.
> ```suggestion
> // Offload the merge and save to a background job to avoid blocking the request
> user.data.mergePending = true;
> req.user = user;
> // Start the merge in the background
> setImmediate(async () => {
> try {
> await user.mergeFromTemporaryUser(existingUser);
> await user.save();
> // Optionally, clear the mergePending flag here if you want to update the user record
> } catch (err) {
> console.error("Background mergeFromTemporaryUser failed:", err);
> }
> });
> next();
> ```

_Originally posted by @Copilot in [#431](https://github.com/CenterForDigitalHumanities/TPEN-services/pull/431/changes#r2608032786)_

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.