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

Author: porcellusCreated Feb 19, 2026Updated Feb 19, 2026

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.

Source: supertokens/supertokens-core