Merge branch 'rework-list'

This commit is contained in:
Zed
2021-12-30 20:51:24 +01:00
7 changed files with 49 additions and 45 deletions

View File

@@ -58,7 +58,7 @@ proc initRedisPool*(cfg: Config) {.async.} =
template pidKey(name: string): string = "pid:" & $(hash(name) div 1_000_000)
template profileKey(name: string): string = "p:" & name
template listKey(l: List): string = toLower("l:" & l.username & '/' & l.name)
template listKey(l: List): string = "l:" & l.id
proc get(query: string): Future[string] {.async.} =
pool.withAcquire(r):
@@ -131,17 +131,17 @@ proc getCachedPhotoRail*(name: string): Future[PhotoRail] {.async.} =
result = await getPhotoRail(name)
await cache(result, name)
proc getCachedList*(username=""; name=""; id=""): Future[List] {.async.} =
let list = if id.len > 0: redisNil
else: await get(toLower("l:" & username & '/' & name))
proc getCachedList*(username=""; slug=""; id=""): Future[List] {.async.} =
let list = if id.len == 0: redisNil
else: await get("l:" & id)
if list != redisNil:
result = fromFlatty(uncompress(list), List)
else:
if id.len > 0:
result = await getGraphListById(id)
result = await getGraphList(id)
else:
result = await getGraphList(username, name)
result = await getGraphListBySlug(username, slug)
await cache(result)
proc getCachedRss*(key: string): Future[Rss] {.async.} =