Skip to content

Background User merging #484

@cubap

Description

@cubap

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.

          // 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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions