mirror of
https://github.com/zedeus/nitter.git
synced 2024-12-22 18:45:31 +00:00
Move RSS compression to Redis module, fix crash
This commit is contained in:
parent
3a076a9b4e
commit
091bb6813d
|
@ -102,7 +102,7 @@ proc cache*(data: Tweet) {.async.} =
|
|||
proc cacheRss*(query: string; rss: Rss) {.async.} =
|
||||
let key = "rss:" & query
|
||||
pool.withAcquire(r):
|
||||
dawait r.hSet(key, "rss", rss.feed)
|
||||
dawait r.hSet(key, "rss", compress(rss.feed))
|
||||
dawait r.hSet(key, "min", rss.cursor)
|
||||
dawait r.expire(key, rssCacheTime)
|
||||
|
||||
|
@ -182,6 +182,9 @@ proc getCachedRss*(key: string): Future[Rss] {.async.} =
|
|||
pool.withAcquire(r):
|
||||
result.cursor = await r.hGet(k, "min")
|
||||
if result.cursor.len > 2:
|
||||
result.feed = await r.hGet(k, "rss")
|
||||
let feed = await r.hGet(k, "rss")
|
||||
if feed != redisNil:
|
||||
try: result.feed = uncompress feed
|
||||
except: echo "Decompressing RSS failed: ", feed
|
||||
else:
|
||||
result.cursor.setLen 0
|
||||
|
|
|
@ -1,14 +1,14 @@
|
|||
# SPDX-License-Identifier: AGPL-3.0-only
|
||||
import asyncdispatch, strutils, tables, times, hashes, uri
|
||||
|
||||
import jester, supersnappy
|
||||
import jester
|
||||
|
||||
import router_utils, timeline
|
||||
import ../query
|
||||
|
||||
include "../views/rss.nimf"
|
||||
|
||||
export times, hashes, supersnappy
|
||||
export times, hashes
|
||||
|
||||
proc timelineRss*(req: Request; cfg: Config; query: Query): Future[Rss] {.async.} =
|
||||
var profile: Profile
|
||||
|
@ -36,7 +36,7 @@ proc timelineRss*(req: Request; cfg: Config; query: Query): Future[Rss] {.async.
|
|||
return Rss(feed: profile.user.username, cursor: "suspended")
|
||||
|
||||
if profile.user.fullname.len > 0:
|
||||
let rss = compress renderTimelineRss(profile, cfg, multi=(names.len > 1))
|
||||
let rss = renderTimelineRss(profile, cfg, multi=(names.len > 1))
|
||||
return Rss(feed: rss, cursor: profile.tweets.bottom)
|
||||
|
||||
template respRss*(rss, page) =
|
||||
|
@ -52,7 +52,7 @@ template respRss*(rss, page) =
|
|||
|
||||
let headers = {"Content-Type": "application/rss+xml; charset=utf-8",
|
||||
"Min-Id": rss.cursor}
|
||||
resp Http200, headers, uncompress rss.feed
|
||||
resp Http200, headers, rss.feed
|
||||
|
||||
proc createRssRouter*(cfg: Config) =
|
||||
router rss:
|
||||
|
@ -75,8 +75,7 @@ proc createRssRouter*(cfg: Config) =
|
|||
|
||||
let tweets = await getSearch[Tweet](query, cursor)
|
||||
rss.cursor = tweets.bottom
|
||||
rss.feed = compress renderSearchRss(tweets.content, query.text,
|
||||
genQueryUrl(query), cfg)
|
||||
rss.feed = renderSearchRss(tweets.content, query.text, genQueryUrl(query), cfg)
|
||||
|
||||
await cacheRss(key, rss)
|
||||
respRss(rss, "Search")
|
||||
|
@ -157,7 +156,7 @@ proc createRssRouter*(cfg: Config) =
|
|||
list = await getCachedList(id=(@"id"))
|
||||
timeline = await getListTimeline(list.id, cursor)
|
||||
rss.cursor = timeline.bottom
|
||||
rss.feed = compress renderListRss(timeline.content, list, cfg)
|
||||
rss.feed = renderListRss(timeline.content, list, cfg)
|
||||
|
||||
await cacheRss(key, rss)
|
||||
respRss(rss, "List")
|
||||
|
|
Loading…
Reference in a new issue