From 735db6c6278f32d662b64eac1a217e85615181d1 Mon Sep 17 00:00:00 2001 From: Sattvik Chakravarthy Date: Thu, 7 Sep 2023 13:58:09 +0530 Subject: [PATCH] fix: account linking stats --- .../java/io/supertokens/ee/EEFeatureFlag.java | 48 ++++++++++++++++++- .../java/io/supertokens/inmemorydb/Start.java | 18 +++++++ 2 files changed, 65 insertions(+), 1 deletion(-) diff --git a/ee/src/main/java/io/supertokens/ee/EEFeatureFlag.java b/ee/src/main/java/io/supertokens/ee/EEFeatureFlag.java index 8efe42552..40eb83bb7 100644 --- a/ee/src/main/java/io/supertokens/ee/EEFeatureFlag.java +++ b/ee/src/main/java/io/supertokens/ee/EEFeatureFlag.java @@ -29,7 +29,6 @@ import io.supertokens.pluginInterface.exceptions.StorageQueryException; import io.supertokens.pluginInterface.multitenancy.AppIdentifier; import io.supertokens.pluginInterface.multitenancy.TenantConfig; -import io.supertokens.pluginInterface.multitenancy.TenantIdentifier; import io.supertokens.pluginInterface.multitenancy.ThirdPartyConfig; import io.supertokens.pluginInterface.multitenancy.exceptions.TenantOrAppNotFoundException; import io.supertokens.pluginInterface.session.sqlStorage.SessionSQLStorage; @@ -264,6 +263,49 @@ private JsonObject getMultiTenancyStats() return stats; } + private JsonObject getAccountLinkingStats() throws StorageQueryException { + JsonObject result = new JsonObject(); + Storage[] storages = StorageLayer.getStoragesForApp(main, this.appIdentifier); + boolean usesAccountLinking = false; + + for (Storage storage : storages) { + if (((AuthRecipeStorage)storage).checkIfUsesAccountLinking(this.appIdentifier)) { + usesAccountLinking = true; + break; + } + } + + result.addProperty("usesAccountLinking", usesAccountLinking); + if (!usesAccountLinking) { + result.addProperty("totalUserCountWithMoreThanOneLoginMethod", 0); + JsonArray mauArray = new JsonArray(); + for (int i = 0; i < 30; i++) { + mauArray.add(new JsonPrimitive(0)); + } + result.add("mauWithMoreThanOneLoginMethod", mauArray); + return result; + } + + int totalUserCountWithMoreThanOneLoginMethod = 0; + int[] maus = new int[30]; + + long now = System.currentTimeMillis(); + long today = now - (now % (24 * 60 * 60 * 1000L)); + + for (Storage storage : storages) { + totalUserCountWithMoreThanOneLoginMethod += ((AuthRecipeStorage)storage).getUsersCountWithMoreThanOneLoginMethod(this.appIdentifier); + + for (int i = 0; i < 30; i++) { + long timestamp = today - (i * 24 * 60 * 60 * 1000L); + maus[i] += ((ActiveUsersStorage)storage).countUsersThatHaveMoreThanOneLoginMethodAndActiveSince(appIdentifier, timestamp); + } + } + + result.addProperty("totalUserCountWithMoreThanOneLoginMethod", totalUserCountWithMoreThanOneLoginMethod); + result.add("mauWithMoreThanOneLoginMethod", new Gson().toJsonTree(maus)); + return result; + } + private JsonArray getMAUs() throws StorageQueryException, TenantOrAppNotFoundException { JsonArray mauArr = new JsonArray(); for (int i = 0; i < 30; i++) { @@ -311,6 +353,10 @@ public JsonObject getPaidFeatureStats() throws StorageQueryException, TenantOrAp if (feature == EE_FEATURES.MULTI_TENANCY) { usageStats.add(EE_FEATURES.MULTI_TENANCY.toString(), getMultiTenancyStats()); } + + if (feature == EE_FEATURES.ACCOUNT_LINKING) { + usageStats.add(EE_FEATURES.ACCOUNT_LINKING.toString(), getAccountLinkingStats()); + } } usageStats.add("maus", getMAUs()); diff --git a/src/main/java/io/supertokens/inmemorydb/Start.java b/src/main/java/io/supertokens/inmemorydb/Start.java index 88bf47678..53e6b831a 100644 --- a/src/main/java/io/supertokens/inmemorydb/Start.java +++ b/src/main/java/io/supertokens/inmemorydb/Start.java @@ -2834,4 +2834,22 @@ public void unlinkAccounts_Transaction(AppIdentifier appIdentifier, TransactionC throws StorageQueryException { // TODO:.. } + + @Override + public boolean checkIfUsesAccountLinking(AppIdentifier appIdentifier) throws StorageQueryException { + // TODO + return false; + } + + @Override + public int countUsersThatHaveMoreThanOneLoginMethodAndActiveSince(AppIdentifier appIdentifier, long sinceTime) throws StorageQueryException { + // TODO + return 0; + } + + @Override + public int getUsersCountWithMoreThanOneLoginMethod(AppIdentifier appIdentifier) throws StorageQueryException { + // TODO + return 0; + } }