Skip to content

Optimize unlinkAccounts (after db schema rework): shortcircuit removeAccountInfoReservation for single-login-method primary user #1225

@porcellus

Description

@porcellus

Context

In AuthRecipe.java (unlinkAccounts), when unlinking a recipe user that IS the primary user and has only 1 login method, we call removeAccountInfoReservationForPrimaryUserForUnlinking_Transaction. This method runs complex NOT IN queries to check which primary_user_tenants
entries are still covered by other linked recipe users.

Optimization

When primaryUser.loginMethods.length == 1, there are no other linked recipe users by definition. The NOT IN subqueries will always return empty results, making the complex logic unnecessary. We could shortcircuit this by directly removing all primary claims for the user.

Location

src/main/java/io/supertokens/authRecipe/AuthRecipe.java — the primaryUser.loginMethods.length == 1 branch in unlinkAccounts.

Impact

Performance optimization only — current behavior is correct.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions