Minor RSS behavior improvements
This commit is contained in:
parent
eadf722284
commit
f10519c41a
|
@ -102,8 +102,9 @@ proc cache*(data: Tweet) {.async.} =
|
||||||
proc cacheRss*(query: string; rss: Rss) {.async.} =
|
proc cacheRss*(query: string; rss: Rss) {.async.} =
|
||||||
let key = "rss:" & query
|
let key = "rss:" & query
|
||||||
pool.withAcquire(r):
|
pool.withAcquire(r):
|
||||||
dawait r.hSet(key, "rss", compress(rss.feed))
|
|
||||||
dawait r.hSet(key, "min", rss.cursor)
|
dawait r.hSet(key, "min", rss.cursor)
|
||||||
|
if rss.cursor != "suspended":
|
||||||
|
dawait r.hSet(key, "rss", compress(rss.feed))
|
||||||
dawait r.expire(key, rssCacheTime)
|
dawait r.expire(key, rssCacheTime)
|
||||||
|
|
||||||
template deserialize(data, T) =
|
template deserialize(data, T) =
|
||||||
|
@ -182,8 +183,9 @@ proc getCachedRss*(key: string): Future[Rss] {.async.} =
|
||||||
pool.withAcquire(r):
|
pool.withAcquire(r):
|
||||||
result.cursor = await r.hGet(k, "min")
|
result.cursor = await r.hGet(k, "min")
|
||||||
if result.cursor.len > 2:
|
if result.cursor.len > 2:
|
||||||
|
if result.cursor != "suspended":
|
||||||
let feed = await r.hGet(k, "rss")
|
let feed = await r.hGet(k, "rss")
|
||||||
if feed != redisNil:
|
if feed.len > 0 and feed != redisNil:
|
||||||
try: result.feed = uncompress feed
|
try: result.feed = uncompress feed
|
||||||
except: echo "Decompressing RSS failed: ", feed
|
except: echo "Decompressing RSS failed: ", feed
|
||||||
else:
|
else:
|
||||||
|
|
|
@ -48,7 +48,7 @@ template respRss*(rss, page) =
|
||||||
|
|
||||||
resp Http404, showError(page & info & "not found", cfg)
|
resp Http404, showError(page & info & "not found", cfg)
|
||||||
elif rss.cursor.len == 9 and rss.cursor == "suspended":
|
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",
|
let headers = {"Content-Type": "application/rss+xml; charset=utf-8",
|
||||||
"Min-Id": rss.cursor}
|
"Min-Id": rss.cursor}
|
||||||
|
|
Loading…
Reference in New Issue