Skip to content

Commit

Permalink
fix: account linking stats
Browse files Browse the repository at this point in the history
  • Loading branch information
sattvikc committed Sep 7, 2023
1 parent d8569da commit 735db6c
Show file tree
Hide file tree
Showing 2 changed files with 65 additions and 1 deletion.
48 changes: 47 additions & 1 deletion ee/src/main/java/io/supertokens/ee/EEFeatureFlag.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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++) {
Expand Down Expand Up @@ -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());
Expand Down
18 changes: 18 additions & 0 deletions src/main/java/io/supertokens/inmemorydb/Start.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}

0 comments on commit 735db6c

Please sign in to comment.