|
@@ -6,6 +6,8 @@ import { P2pStorageIpfsProvider } from "../p2p-storage-ipfs/p2p-storage-ipfs";
|
|
|
|
|
|
@Injectable()
|
|
|
export class FeedProvider {
|
|
|
+ friends;
|
|
|
+
|
|
|
constructor(
|
|
|
private http: HttpClient,
|
|
|
private twitter: TwitterApiProvider,
|
|
@@ -65,7 +67,7 @@ export class FeedProvider {
|
|
|
const intervalEnd: Date = this.getOldestTweetTimestamp(tweets);
|
|
|
|
|
|
// Fetch user's friends
|
|
|
- const friends = await this.twitter.fetchFriends(userId);
|
|
|
+ const friends = await this.getCachedFriends(userId);
|
|
|
|
|
|
let privateTweetHashs = [];
|
|
|
friends.forEach(async friend => {
|
|
@@ -136,4 +138,15 @@ export class FeedProvider {
|
|
|
return 0;
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+ private async getCachedFriends(userId) {
|
|
|
+ // Cache friends for 15 minutes to avoid unnecessary API calls
|
|
|
+ if (!this.friends || (Date.now() - this.friends.lastUpdate) / 900000 > 15) {
|
|
|
+ this.friends = {
|
|
|
+ friendList: await this.twitter.fetchFriends(userId),
|
|
|
+ lastUpdate: Date.now()
|
|
|
+ };
|
|
|
+ }
|
|
|
+ return this.friends.friendList;
|
|
|
+ }
|
|
|
}
|