Skip to content

Commit

Permalink
Merge pull request #1782 from augchan42/fix/twitter-profile-cache-1638
Browse files Browse the repository at this point in the history
fix: remove twitter profile caching (#1638)
  • Loading branch information
odilitime authored Jan 5, 2025
2 parents ed16b0c + 6b0ae6e commit 0e106cf
Showing 1 changed file with 1 addition and 22 deletions.
23 changes: 1 addition & 22 deletions packages/client-twitter/src/base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -729,28 +729,10 @@ export class ClientBase extends EventEmitter {
);
}

async getCachedProfile(username: string) {
return await this.runtime.cacheManager.get<TwitterProfile>(
`twitter/${username}/profile`
);
}

async cacheProfile(profile: TwitterProfile) {
await this.runtime.cacheManager.set(
`twitter/${profile.username}/profile`,
profile
);
}

async fetchProfile(username: string): Promise<TwitterProfile> {
const cached = await this.getCachedProfile(username);

if (cached) return cached;

try {
const profile = await this.requestQueue.add(async () => {
const profile = await this.twitterClient.getProfile(username);
// console.log({ profile });
return {
id: profile.userId,
username,
Expand All @@ -767,13 +749,10 @@ export class ClientBase extends EventEmitter {
} satisfies TwitterProfile;
});

this.cacheProfile(profile);

return profile;
} catch (error) {
console.error("Error fetching Twitter profile:", error);

return undefined;
throw error;
}
}
}

0 comments on commit 0e106cf

Please sign in to comment.