mirror of
https://github.com/snachodog/tok-to-insta-follower-bridge.git
synced 2025-04-17 17:22:23 -06:00
cache clients
This commit is contained in:
parent
b4f7871672
commit
cf36e9cd4e
@ -1,5 +1,8 @@
|
|||||||
import { AtUri, type AtpSessionData, BskyAgent } from "@atproto/api";
|
import { AtUri, type AtpSessionData, BskyAgent } from "@atproto/api";
|
||||||
|
|
||||||
|
// try and cut down the amount of session resumes by caching the clients
|
||||||
|
const clientCache = new Map<string, BskyClient>()
|
||||||
|
|
||||||
export type BskyLoginParams = {
|
export type BskyLoginParams = {
|
||||||
identifier: string;
|
identifier: string;
|
||||||
password: string;
|
password: string;
|
||||||
@ -25,15 +28,21 @@ export class BskyClient {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static createAgentFromSession(session: AtpSessionData): BskyClient {
|
public static createAgentFromSession(session: AtpSessionData): BskyClient {
|
||||||
const client = new BskyClient();
|
if (clientCache.has(session.did)) {
|
||||||
client.agent.resumeSession(session);
|
return clientCache.get(session.did)
|
||||||
client.me = {
|
} else {
|
||||||
did: session.did,
|
const client = new BskyClient();
|
||||||
handle: session.handle,
|
client.agent.resumeSession(session);
|
||||||
email: session.email,
|
client.me = {
|
||||||
};
|
did: session.did,
|
||||||
|
handle: session.handle,
|
||||||
|
email: session.email,
|
||||||
|
};
|
||||||
|
|
||||||
return client;
|
clientCache.set(session.did, client);
|
||||||
|
|
||||||
|
return client;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static async createAgent({
|
public static async createAgent({
|
||||||
@ -50,6 +59,9 @@ export class BskyClient {
|
|||||||
handle: data.handle,
|
handle: data.handle,
|
||||||
email: data.email,
|
email: data.email,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
clientCache.set(data.did, client);
|
||||||
|
|
||||||
return client;
|
return client;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user