Minor RSS behavior improvements

This commit is contained in:
Zed 2022-01-27 14:46:24 +01:00
parent eadf722284
commit f10519c41a
2 changed files with 8 additions and 6 deletions

View File

@ -102,8 +102,9 @@ proc cache*(data: Tweet) {.async.} =
proc cacheRss*(query: string; rss: Rss) {.async.} =
let key = "rss:" & query
pool.withAcquire(r):
dawait r.hSet(key, "rss", compress(rss.feed))
dawait r.hSet(key, "min", rss.cursor)
if rss.cursor != "suspended":
dawait r.hSet(key, "rss", compress(rss.feed))
dawait r.expire(key, rssCacheTime)
template deserialize(data, T) =
@ -182,9 +183,10 @@ proc getCachedRss*(key: string): Future[Rss] {.async.} =
pool.withAcquire(r):
result.cursor = await r.hGet(k, "min")
if result.cursor.len > 2:
let feed = await r.hGet(k, "rss")
if feed != redisNil:
try: result.feed = uncompress feed
except: echo "Decompressing RSS failed: ", feed
if result.cursor != "suspended":
let feed = await r.hGet(k, "rss")
if feed.len > 0 and feed != redisNil:
try: result.feed = uncompress feed
except: echo "Decompressing RSS failed: ", feed
else:
result.cursor.setLen 0

View File

@ -48,7 +48,7 @@ template respRss*(rss, page) =
resp Http404, showError(page & info & "not found", cfg)
elif rss.cursor.len == 9 and rss.cursor == "suspended":
resp Http404, showError(getSuspended(rss.feed), cfg)
resp Http404, showError(getSuspended(@"name"), cfg)
let headers = {"Content-Type": "application/rss+xml; charset=utf-8",
"Min-Id": rss.cursor}