Implement user_id to screen_name router
This commit is contained in:
@@ -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))
|
||||
|
||||
Reference in New Issue
Block a user