Skip to content

Conversation

@sattvikc
Copy link
Collaborator

Summary of change

(A few sentences about this PR)

Related issues

  • Link to issue1 here
  • Link to issue1 here

Test Plan

(Write your test plan here. If you changed any code, please provide us with clear instructions on how you verified your
changes work. Bonus points for screenshots and videos!)

Documentation changes

(If relevant, please create a PR in our docs repo, or create a checklist here
highlighting the necessary changes)

Checklist for important updates

  • Changelog has been updated
  • pluginInterfaceSupported.json file has been updated (if needed)
  • Changes to the version if needed
    • In build.gradle
  • Had installed and ran the pre-commit hook
  • If there are new dependencies that have been added in build.gradle, please make sure to add them
    in implementationDependencies.json.
  • Issue this PR against the latest non released version branch.
    • To know which one it is, run find the latest released tag (git tag) in the format vX.Y.Z, and then find the
      latest branch (git branch --all) whose X.Y is greater than the latest released tag.
    • If no such branch exists, then create one from the latest released branch.
  • When adding new recipes, ensure that its performance is being measured in the OneMillionUsersTest

Remaining TODOs for this PR

  • Item1
  • Item2

Comment on lines 3555 to +3559
GeneralQueries.linkAccounts_Transaction(this, sqlCon, appIdentifier, recipeUserId, primaryUserId);
AccountInfoQueries.reserveAccountInfoForLinking_Transaction(this, sqlCon, appIdentifier, recipeUserId, primaryUserId);
Copy link
Collaborator

Choose a reason for hiding this comment

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

Is the idea here that we can just drop the GeneralQueries one sooner or later?

Comment on lines +246 to +249
{
io.supertokens.storage.postgresql.queries.Utils.takeAdvisoryLock(
sqlCon, tenantConfig.tenantIdentifier.getConnectionUriDomain() + "~" + tenantConfig.tenantIdentifier.getAppId() + "~" + tenantConfig.tenantIdentifier.getTenantId());
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

Do we need this? What do we want to achieve with this here?

// Insert row for third party id
AccountInfoQueries.addRecipeUserAccountInfo_Transaction(start, sqlCon, tenantIdentifier, id,
THIRD_PARTY.toString(), ACCOUNT_INFO_TYPE.THIRD_PARTY, "", "",
thirdParty.id + "::" + thirdParty.userId);
Copy link
Collaborator

Choose a reason for hiding this comment

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

Do we validate the thirdParty.id cannot have "::"?

Comment on lines +72 to +74
+ "account_info_value TEXT NOT NULL,"
+ "third_party_id VARCHAR(28),"
+ "third_party_user_id VARCHAR(256),"
Copy link
Collaborator

Choose a reason for hiding this comment

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

We could also add a check constraint about "valid combinations" (i.e., tp+email or email or phone), but I don't think we actually need that. Please think it through and document the decision.

List<Object> parameters = new ArrayList<>();

// Add app_id parameter
parameters.add(appIdentifier.getAppId());
Copy link
Collaborator

Choose a reason for hiding this comment

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

Please move these right below/above where we add the ? this will replace.

Connection sqlCon = (Connection) con.getConnection();

// Build the query dynamically based on which values are not null
StringBuilder QUERY = new StringBuilder("SELECT primary_user_id, account_info_type FROM " + getConfig(start).getPrimaryUserTenantsTable());
Copy link
Collaborator

Choose a reason for hiding this comment

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

Couldn't we do this similarly to how the addPrimaryUserAccountInfo_Transaction, using a subquery based on the recipe user id?

}
}

public static void checkIfLoginMethodsCanBeLinked_Transaction(Start start, TransactionConnection con, AppIdentifier appIdentifier, Set<String> tenantIds, Set<String> emails,
Copy link
Collaborator

Choose a reason for hiding this comment

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

Please see if it makes sense to use a subquery here instead of the collected emails

if (thirdParties != null && !thirdParties.isEmpty()) {
List<String> thirdPartyValues = new ArrayList<>();
for (LoginMethod.ThirdParty tp : thirdParties) {
thirdPartyValues.add(tp.id + "::" + tp.userId);
Copy link
Collaborator

Choose a reason for hiding this comment

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

We should extract the concatenation into a single util function, just to ensure this stays consistent.

Comment on lines +319 to +327
StringBuilder QUERY = new StringBuilder("SELECT primary_user_id, account_info_type, account_info_value FROM ");
QUERY.append(getConfig(start).getPrimaryUserTenantsTable());
QUERY.append(" WHERE app_id = ? AND tenant_id IN (");
for (int i = 0; i < tenantIdsList.size(); i++) {
QUERY.append("?");
if (i != tenantIdsList.size() - 1) {
QUERY.append(",");
}
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

Please group this together with adding the params.

// 1) recipe user's account info -> all tenants of primary user
String QUERY_1 = "INSERT INTO " + primaryUserTenantsTable
+ " (app_id, tenant_id, account_info_type, account_info_value, primary_user_id)"
+ " SELECT ?, primary_tenants.tenant_id, recipe_ai.account_info_type, recipe_ai.account_info_value, ?"
Copy link
Collaborator

Choose a reason for hiding this comment

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

We may want to add explicit types when using a parameter in the subselect "result" directly

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.

3 participants