Parse user stats as ints, not strings, cleanup

This commit is contained in:
Zed 2022-01-16 03:32:18 +01:00
parent 54330f0b0c
commit fcfc1ef497
6 changed files with 18 additions and 19 deletions

View File

@ -14,11 +14,11 @@ proc parseProfile(js: JsonNode; id=""): Profile =
bio: js{"description"}.getStr, bio: js{"description"}.getStr,
userPic: js{"profile_image_url_https"}.getImageStr.replace("_normal", ""), userPic: js{"profile_image_url_https"}.getImageStr.replace("_normal", ""),
banner: js.getBanner, banner: js.getBanner,
following: $js{"friends_count"}.getInt, following: js{"friends_count"}.getInt,
followers: $js{"followers_count"}.getInt, followers: js{"followers_count"}.getInt,
tweets: $js{"statuses_count"}.getInt, tweets: js{"statuses_count"}.getInt,
likes: $js{"favourites_count"}.getInt, likes: js{"favourites_count"}.getInt,
media: $js{"media_count"}.getInt, media: js{"media_count"}.getInt,
verified: js{"verified"}.getBool, verified: js{"verified"}.getBool,
protected: js{"protected"}.getBool, protected: js{"protected"}.getBool,
joinDate: js{"created_at"}.getTime joinDate: js{"created_at"}.getTime

View File

@ -47,6 +47,7 @@ proc initRedisPool*(cfg: Config) {.async.} =
await migrate("snappyRss", "rss:*") await migrate("snappyRss", "rss:*")
await migrate("userBuckets", "p:*") await migrate("userBuckets", "p:*")
await migrate("profileDates", "p:*") await migrate("profileDates", "p:*")
await migrate("profileStats", "p:*")
pool.withAcquire(r): pool.withAcquire(r):
# optimize memory usage for profile ID buckets # optimize memory usage for profile ID buckets

View File

@ -19,8 +19,7 @@ proc timelineRss*(req: Request; cfg: Config; query: Query): Future[Rss] {.async.
names = getNames(name) names = getNames(name)
if names.len == 1: if names.len == 1:
(profile, timeline) = (profile, timeline) = await fetchTimeline(after, query, skipRail=true)
await fetchSingleTimeline(after, query, skipRail=true)
else: else:
var q = query var q = query
q.fromUser = names q.fromUser = names

View File

@ -19,7 +19,7 @@ proc getQuery*(request: Request; tab, name: string): Query =
of "search": initQuery(params(request), name=name) of "search": initQuery(params(request), name=name)
else: Query(fromUser: @[name]) else: Query(fromUser: @[name])
proc fetchSingleTimeline*(after: string; query: Query; skipRail=false): proc fetchTimeline*(after: string; query: Query; skipRail=false):
Future[(Profile, Timeline, PhotoRail)] {.async.} = Future[(Profile, Timeline, PhotoRail)] {.async.} =
let name = query.fromUser[0] let name = query.fromUser[0]
@ -86,7 +86,7 @@ proc showTimeline*(request: Request; query: Query; cfg: Config; prefs: Prefs;
html = renderTweetSearch(timeline, prefs, getPath()) html = renderTweetSearch(timeline, prefs, getPath())
return renderMain(html, request, cfg, prefs, "Multi", rss=rss) return renderMain(html, request, cfg, prefs, "Multi", rss=rss)
var (p, t, r) = await fetchSingleTimeline(after, query) var (p, t, r) = await fetchTimeline(after, query)
if p.suspended: return showError(getSuspended(p.username), cfg) if p.suspended: return showError(getSuspended(p.username), cfg)
if p.id.len == 0: return if p.id.len == 0: return
@ -139,7 +139,7 @@ proc createTimelineRouter*(cfg: Config) =
timeline.beginning = true timeline.beginning = true
resp $renderTweetSearch(timeline, prefs, getPath()) resp $renderTweetSearch(timeline, prefs, getPath())
else: else:
var (_, timeline, _) = await fetchSingleTimeline(after, query, skipRail=true) var (_, timeline, _) = await fetchTimeline(after, query, skipRail=true)
if timeline.content.len == 0: resp Http404 if timeline.content.len == 0: resp Http404
timeline.beginning = true timeline.beginning = true
resp $renderTimelineTweets(timeline, prefs, getPath()) resp $renderTimelineTweets(timeline, prefs, getPath())

View File

@ -48,17 +48,16 @@ type
id*: string id*: string
username*: string username*: string
fullname*: string fullname*: string
lowername*: string
location*: string location*: string
website*: string website*: string
bio*: string bio*: string
userPic*: string userPic*: string
banner*: string banner*: string
following*: string following*: int
followers*: string followers*: int
tweets*: string tweets*: int
likes*: string likes*: int
media*: string media*: int
verified*: bool verified*: bool
protected*: bool protected*: bool
suspended*: bool suspended*: bool

View File

@ -5,12 +5,12 @@ import karax/[karaxdsl, vdom, vstyles]
import renderutils, search import renderutils, search
import ".."/[types, utils, formatters] import ".."/[types, utils, formatters]
proc renderStat(num, class: string; text=""): VNode = proc renderStat(num: int; class: string; text=""): VNode =
let t = if text.len > 0: text else: class let t = if text.len > 0: text else: class
buildHtml(li(class=class)): buildHtml(li(class=class)):
span(class="profile-stat-header"): text capitalizeAscii(t) span(class="profile-stat-header"): text capitalizeAscii(t)
span(class="profile-stat-num"): span(class="profile-stat-num"):
text if num.len == 0: "?" else: insertSep(num, ',') text insertSep($num, ',')
proc renderProfileCard*(profile: Profile; prefs: Prefs): VNode = proc renderProfileCard*(profile: Profile; prefs: Prefs): VNode =
buildHtml(tdiv(class="profile-card")): buildHtml(tdiv(class="profile-card")):