Reduce usage of strformat, minor perf improvement
This commit is contained in:
@@ -10,6 +10,11 @@ include "../views/rss.nimf"
|
||||
|
||||
export times, hashes
|
||||
|
||||
proc redisKey*(page, name, cursor: string): string =
|
||||
result = page & ":" & name
|
||||
if cursor.len > 0:
|
||||
result &= ":" & cursor
|
||||
|
||||
proc timelineRss*(req: Request; cfg: Config; query: Query): Future[Rss] {.async.} =
|
||||
var profile: Profile
|
||||
let
|
||||
@@ -42,8 +47,8 @@ proc timelineRss*(req: Request; cfg: Config; query: Query): Future[Rss] {.async.
|
||||
template respRss*(rss, page) =
|
||||
if rss.cursor.len == 0:
|
||||
let info = case page
|
||||
of "User": &""" "{@"name"}" """
|
||||
of "List": &""" "{@"id"}" """
|
||||
of "User": " \"" & @"name" & "\" "
|
||||
of "List": " \"" & @"id" & "\" "
|
||||
else: " "
|
||||
|
||||
resp Http404, showError(page & info & "not found", cfg)
|
||||
@@ -67,7 +72,7 @@ proc createRssRouter*(cfg: Config) =
|
||||
|
||||
let
|
||||
cursor = getCursor()
|
||||
key = &"search:{hash(genQueryUrl(query))}:cursor"
|
||||
key = redisKey("search", $hash(genQueryUrl(query)), cursor)
|
||||
|
||||
var rss = await getCachedRss(key)
|
||||
if rss.cursor.len > 0:
|
||||
@@ -84,9 +89,8 @@ proc createRssRouter*(cfg: Config) =
|
||||
cond cfg.enableRss
|
||||
cond '.' notin @"name"
|
||||
let
|
||||
cursor = getCursor()
|
||||
name = @"name"
|
||||
key = &"twitter:{name}:{cursor}"
|
||||
key = redisKey("twitter", name, getCursor())
|
||||
|
||||
var rss = await getCachedRss(key)
|
||||
if rss.cursor.len > 0:
|
||||
@@ -101,18 +105,20 @@ proc createRssRouter*(cfg: Config) =
|
||||
cond cfg.enableRss
|
||||
cond '.' notin @"name"
|
||||
cond @"tab" in ["with_replies", "media", "search"]
|
||||
let name = @"name"
|
||||
let query =
|
||||
case @"tab"
|
||||
of "with_replies": getReplyQuery(name)
|
||||
of "media": getMediaQuery(name)
|
||||
of "search": initQuery(params(request), name=name)
|
||||
else: Query(fromUser: @[name])
|
||||
let
|
||||
name = @"name"
|
||||
tab = @"tab"
|
||||
query =
|
||||
case tab
|
||||
of "with_replies": getReplyQuery(name)
|
||||
of "media": getMediaQuery(name)
|
||||
of "search": initQuery(params(request), name=name)
|
||||
else: Query(fromUser: @[name])
|
||||
|
||||
var key = &"""{@"tab"}:{@"name"}:"""
|
||||
if @"tab" == "search":
|
||||
key &= $hash(genQueryUrl(query)) & ":"
|
||||
key &= getCursor()
|
||||
let searchKey = if tab != "search": ""
|
||||
else: ":" & $hash(genQueryUrl(query))
|
||||
|
||||
let key = redisKey(tab, name & searchKey, getCursor())
|
||||
|
||||
var rss = await getCachedRss(key)
|
||||
if rss.cursor.len > 0:
|
||||
@@ -132,28 +138,27 @@ proc createRssRouter*(cfg: Config) =
|
||||
cursor = getCursor()
|
||||
|
||||
if list.id.len == 0:
|
||||
resp Http404, showError(&"""List "{@"slug"}" not found""", cfg)
|
||||
resp Http404, showError("List \"" & @"slug" & "\" not found", cfg)
|
||||
|
||||
let url = &"/i/lists/{list.id}/rss"
|
||||
let url = "/i/lists/" & list.id & "/rss"
|
||||
if cursor.len > 0:
|
||||
redirect(&"{url}?cursor={encodeUrl(cursor, false)}")
|
||||
redirect(url & "?cursor=" & encodeUrl(cursor, false))
|
||||
else:
|
||||
redirect(url)
|
||||
|
||||
get "/i/lists/@id/rss":
|
||||
cond cfg.enableRss
|
||||
let
|
||||
id = @"id"
|
||||
cursor = getCursor()
|
||||
key =
|
||||
if cursor.len == 0: "lists:" & @"id"
|
||||
else: &"""lists:{@"id"}:{cursor}"""
|
||||
key = redisKey("lists", id, cursor)
|
||||
|
||||
var rss = await getCachedRss(key)
|
||||
if rss.cursor.len > 0:
|
||||
respRss(rss, "List")
|
||||
|
||||
let
|
||||
list = await getCachedList(id=(@"id"))
|
||||
list = await getCachedList(id=id)
|
||||
timeline = await getListTimeline(list.id, cursor)
|
||||
rss.cursor = timeline.bottom
|
||||
rss.feed = renderListRss(timeline.content, list, cfg)
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
# SPDX-License-Identifier: AGPL-3.0-only
|
||||
import strutils, strformat, uri
|
||||
import strutils, uri
|
||||
|
||||
import jester
|
||||
|
||||
@@ -37,7 +37,7 @@ proc createSearchRouter*(cfg: Config) =
|
||||
resp Http404, showError("Invalid search", cfg)
|
||||
|
||||
get "/hashtag/@hash":
|
||||
redirect(&"""/search?q={encodeUrl("#" & @"hash")}""")
|
||||
redirect("/search?q=" & encodeUrl("#" & @"hash"))
|
||||
|
||||
get "/opensearch":
|
||||
let url = getUrlPrefix(cfg) & "/search?q="
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
# SPDX-License-Identifier: AGPL-3.0-only
|
||||
import asyncdispatch, strutils, strformat, sequtils, uri, options, times
|
||||
import asyncdispatch, strutils, sequtils, uri, options, times
|
||||
import jester, karax/vdom
|
||||
|
||||
import router_utils
|
||||
@@ -102,7 +102,7 @@ proc showTimeline*(request: Request; query: Query; cfg: Config; prefs: Prefs;
|
||||
template respTimeline*(timeline: typed) =
|
||||
let t = timeline
|
||||
if t.len == 0:
|
||||
resp Http404, showError(&"""User "{@"name"}" not found""", cfg)
|
||||
resp Http404, showError("User \"" & @"name" & "\" not found", cfg)
|
||||
resp t
|
||||
|
||||
template respUserId*() =
|
||||
|
||||
Reference in New Issue
Block a user