Skip to content

Commit 7144b79

Browse files
committed
feat: add getClientIds and load accounts on startup
1 parent c6ba9eb commit 7144b79

2 files changed

Lines changed: 30 additions & 3 deletions

File tree

src/components/services/account.ts

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,3 +74,25 @@ export async function getAccountCount(): Promise<number> {
7474
return 0;
7575
}
7676
}
77+
78+
export async function getClientIds(): Promise<Map<string, boolean>> {
79+
try {
80+
const accounts = await prisma.account.findMany({
81+
select: {
82+
clientId: true,
83+
isRoot: true,
84+
},
85+
});
86+
87+
const clientIds = new Map<string, boolean>();
88+
accounts.forEach((account) => {
89+
clientIds.set(account.clientId, account.isRoot);
90+
});
91+
92+
return clientIds;
93+
} catch (error) {
94+
Sentry.captureException(error);
95+
log.error("Database", "Failed to get client IDs.", error);
96+
return new Map<string, boolean>();
97+
}
98+
}

src/index.ts

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import {
1616
PHISHTANK_AUTO_UPDATE,
1717
PROJECT_THRESHOLD_MEMORY,
1818
} from "./config";
19-
import { getRootAccount } from "./components/services/account";
19+
import { getClientIds, getRootAccount } from "./components/services/account";
2020

2121
const monitor = new MemoryMonitor({
2222
interval: 60000,
@@ -39,8 +39,13 @@ async function main() {
3939
]);
4040

4141
phishingSet = phishtank.getPhishingSet();
42-
const rootClientId = await getRootAccount();
43-
await addAccount(rootClientId, undefined, true);
42+
43+
const accountsIds = await getClientIds();
44+
await Promise.all(
45+
Array.from(accountsIds.entries()).map(async ([clientId, isRoot]) => {
46+
await addAccount(clientId, undefined, isRoot);
47+
}),
48+
);
4449

4550
await mapCommands();
4651
// Watch for changes

0 commit comments

Comments
 (0)