Implement user_id to screen_name router

This commit is contained in:
jackyzy823
2021-10-04 11:03:40 +01:00
parent aa2fed19d7
commit 52af6b2746
5 changed files with 48 additions and 3 deletions

View File

@@ -78,6 +78,7 @@ proc cache*(data: Profile) {.async.} =
pool.withAcquire(r):
r.startPipelining()
discard await r.setex(name.profileKey, baseCacheTime, compress(toFlatty(data)))
discard await r.setex("i:" & data.id , baseCacheTime, data.username)
discard await r.hset(name.pidKey, name, data.id)
discard await r.flushPipeline()
@@ -110,6 +111,15 @@ proc getCachedProfile*(username: string; fetch=true): Future[Profile] {.async.}
elif fetch:
result = await getProfile(username)
proc getCachedProfileScreenName*(userId: string): Future[string] {.async.} =
let username = await get("i:" & userId)
if username != redisNil:
result = username
else:
let profile = await getProfileById(userId)
result = profile.username
await cache(profile)
proc getCachedPhotoRail*(name: string): Future[PhotoRail] {.async.} =
if name.len == 0: return
let rail = await get("pr:" & toLower(name))