diff --git a/CHANGELOG.md b/CHANGELOG.md index 903c54e9b..8f2683a17 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,19 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). +## [7.0.14] - 2023-11-21 + +- Updates test user query speed + +### Migration + +If using MySQL plugin, run the following SQL script: + +```sql +CREATE INDEX app_id_to_user_id_primary_user_id_index ON app_id_to_user_id (primary_or_recipe_user_id); +CREATE INDEX app_id_to_user_id_user_id_index ON app_id_to_user_id (user_id); +``` + ## [7.0.13] - 2023-11-21 - Adds test to user query speed diff --git a/build.gradle b/build.gradle index 3e2e611f9..fe0b6699d 100644 --- a/build.gradle +++ b/build.gradle @@ -19,7 +19,7 @@ compileTestJava { options.encoding = "UTF-8" } // } //} -version = "7.0.13" +version = "7.0.14" repositories { diff --git a/src/test/java/io/supertokens/test/accountlinking/TestGetUserSpeed.java b/src/test/java/io/supertokens/test/accountlinking/TestGetUserSpeed.java index 4e15bc942..de6a8f890 100644 --- a/src/test/java/io/supertokens/test/accountlinking/TestGetUserSpeed.java +++ b/src/test/java/io/supertokens/test/accountlinking/TestGetUserSpeed.java @@ -36,6 +36,12 @@ import java.util.ArrayList; import java.util.List; import java.util.Random; +import java.util.concurrent.ExecutorService; +import java.util.concurrent.Executors; +import java.util.concurrent.TimeUnit; +import java.util.concurrent.atomic.AtomicInteger; +import java.util.concurrent.locks.Lock; +import java.util.concurrent.locks.ReentrantLock; import static org.junit.Assert.assertNotNull; @@ -57,6 +63,9 @@ public void beforeEach() { public void testUserCreationLinkingAndGetByIdSpeeds() throws Exception { String[] args = {"../"}; TestingProcessManager.TestingProcess process = TestingProcessManager.start(args, false); + Utils.setValueInConfig("postgresql_connection_pool_size", "100"); + Utils.setValueInConfig("mysql_connection_pool_size", "100"); + FeatureFlagTestContent.getInstance(process.getProcess()) .setKeyValue(FeatureFlagTestContent.ENABLED_FEATURES, new EE_FEATURES[]{ EE_FEATURES.ACCOUNT_LINKING, EE_FEATURES.MULTI_TENANCY}); @@ -67,10 +76,6 @@ public void testUserCreationLinkingAndGetByIdSpeeds() throws Exception { return; } - if (!Version.getVersion(process.getProcess()).getPluginName().equals("postgresql")) { - return; - } - if (StorageLayer.isInMemDb(process.getProcess())) { return; } @@ -78,24 +83,42 @@ public void testUserCreationLinkingAndGetByIdSpeeds() throws Exception { int numberOfUsers = 10000; List userIds = new ArrayList<>(); List userIds2 = new ArrayList<>(); + Lock lock = new ReentrantLock(); { + ExecutorService es = Executors.newFixedThreadPool(32); long start = System.currentTimeMillis(); for (int i = 0; i < numberOfUsers; i++) { - String email = "user" + i + "@example.com"; - AuthRecipeUserInfo user = ThirdParty.signInUp( - process.getProcess(), "google", "googleid" + i, email).user; - userIds.add(user.getSupertokensUserId()); - userIds2.add(user.getSupertokensUserId()); + int finalI = i; + es.execute(() -> { + try { + String email = "user" + finalI + "@example.com"; + AuthRecipeUserInfo user = ThirdParty.signInUp( + process.getProcess(), "google", "googleid" + finalI, email).user; + lock.lock(); + userIds.add(user.getSupertokensUserId()); + userIds2.add(user.getSupertokensUserId()); + lock.unlock(); + } catch (Exception e) { + throw new RuntimeException(e); + } + }); } + es.shutdown(); + es.awaitTermination(5, TimeUnit.MINUTES); + long end = System.currentTimeMillis(); - assert end - start < 100000; // 100 sec + System.out.println("Created users " + numberOfUsers + " in " + (end - start) + "ms"); + assert end - start < 25000; // 25 sec } - Thread.sleep(20000); // wait for indexing to finish + Thread.sleep(10000); // wait for index { // Randomly link accounts long start = System.currentTimeMillis(); + ExecutorService es = Executors.newFixedThreadPool(32); + AtomicInteger numberOflinks = new AtomicInteger(0); + while (userIds.size() > 0) { int numUsersToLink = new Random().nextInt(3) + 1; if (numUsersToLink > userIds.size()) { @@ -107,27 +130,46 @@ public void testUserCreationLinkingAndGetByIdSpeeds() throws Exception { usersToLink.add(userIds.get(index)); userIds.remove(index); } + numberOflinks.incrementAndGet(); + + es.execute(() -> { + try { + AuthRecipe.createPrimaryUser(process.getProcess(), usersToLink.get(0)); + for (int i = 1; i < usersToLink.size(); i++) { + AuthRecipe.linkAccounts(process.getProcess(), usersToLink.get(i), usersToLink.get(0)); + } + } catch (Exception e) { + throw new RuntimeException(e); + } + }); - AuthRecipe.createPrimaryUser(process.getProcess(), usersToLink.get(0)); - for (int i = 1; i < usersToLink.size(); i++) { - AuthRecipe.linkAccounts(process.getProcess(), usersToLink.get(i), usersToLink.get(0)); - } } + es.shutdown(); + es.awaitTermination(5, TimeUnit.MINUTES); long end = System.currentTimeMillis(); + System.out.println("Accounts linked in " + (end - start) + "ms"); assert end - start < 50000; // 50 sec } - Thread.sleep(20000); // wait for indexing to finish + Thread.sleep(10000); // wait for index { + ExecutorService es = Executors.newFixedThreadPool(32); long start = System.currentTimeMillis(); for (String userId : userIds2) { - AuthRecipe.getUserById(process.getProcess(), userId); + es.execute(() -> { + try { + AuthRecipe.getUserById(process.getProcess(), userId); + } catch (Exception e) { + throw new RuntimeException(e); + } + }); } + es.shutdown(); + es.awaitTermination(5, TimeUnit.MINUTES); long end = System.currentTimeMillis(); System.out.println("Time taken for " + numberOfUsers + " users: " + (end - start) + "ms"); - - assert end - start < 20000; + assert end - start < 20000; // 20 sec } process.kill();