Skip to content

Commit

Permalink
remove moize from follow check
Browse files Browse the repository at this point in the history
  • Loading branch information
Bossett committed Dec 31, 2024
1 parent 17993ca commit 165cbb2
Showing 1 changed file with 11 additions and 7 deletions.
18 changes: 11 additions & 7 deletions src/addn/getUserFollows.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,17 @@
import { BskyAgent } from '@atproto/api'
import resolveHandleToDID from './resolveHandleToDID'
import moize from 'moize'
import limit from './rateLimit'

export const _getUserFollows = async (user: string, agent: BskyAgent) => {
const followCache = new Map<string, { date: number; follows: string[] }>()

export const getUserFollows = async (user: string, agent: BskyAgent) => {
if (followCache.has(user)) {
if (followCache.get(user)!.date > Date.now() - 1000 * 60 * 10) {
return followCache.get(user)!.follows
}
followCache.delete(user)
}

let user_did = ''
const follows: string[] = []

Expand All @@ -29,12 +37,8 @@ export const _getUserFollows = async (user: string, agent: BskyAgent) => {
})
} while (cursor !== undefined && cursor !== '')

followCache.set(user, { date: Date.now(), follows })
return follows
}

export const getUserFollows = moize(_getUserFollows, {
isPromise: true,
maxAge: 1000 * 60 * 10, // 10 minutes
})

export default getUserFollows

0 comments on commit 165cbb2

Please sign in to comment.