[core] Optimize get config
This commit is contained in:
1 parent
0e95890ca4
commit
0ce4c01c48
2 files changed
+24
No files matched your search
@@ -8,6 +8,10 @@ export abstract class ISessionConfigRepository {
|
||||
|
||||
abstract getConfig(sessionName: string): Promise<SessionConfig | null>;
|
||||
|
||||
abstract getConfigBySessions(
|
||||
sessionNames: string[],
|
||||
): Promise<Map<string, SessionConfig | null>>;
|
||||
|
||||
abstract exists(sessionName: string): Promise<boolean>;
|
||||
|
||||
abstract deleteConfig(sessionName: string): Promise<void>;
|
||||
|
||||
@@ -48,6 +48,26 @@ export class LocalSessionConfigRepository extends ISessionConfigRepository {
|
||||
return JSON.parse(content);
|
||||
}
|
||||
|
||||
async getConfigBySessions(
|
||||
sessionNames: string[],
|
||||
): Promise<Map<string, SessionConfig | null>> {
|
||||
const result = new Map<string, SessionConfig | null>();
|
||||
const uniqueNames = Array.from(new Set(sessionNames));
|
||||
if (uniqueNames.length === 0) {
|
||||
return result;
|
||||
}
|
||||
const items = await Promise.all(
|
||||
uniqueNames.map(async (sessionName) => ({
|
||||
sessionName,
|
||||
config: await this.getConfig(sessionName),
|
||||
})),
|
||||
);
|
||||
for (const item of items) {
|
||||
result.set(item.sessionName, item.config ?? null);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
async saveConfig(sessionName: string, config: SessionConfig) {
|
||||
// Create a folder if not exist
|
||||
const folder = this.store.getSessionDirectory(sessionName);
|
||||
|
||||
Reference in new issue
Block a user