Parse user stats as ints, not strings, cleanup
This commit is contained in:
		
							parent
							
								
									54330f0b0c
								
							
						
					
					
						commit
						fcfc1ef497
					
				| 
						 | 
				
			
			@ -14,11 +14,11 @@ proc parseProfile(js: JsonNode; id=""): Profile =
 | 
			
		|||
    bio: js{"description"}.getStr,
 | 
			
		||||
    userPic: js{"profile_image_url_https"}.getImageStr.replace("_normal", ""),
 | 
			
		||||
    banner: js.getBanner,
 | 
			
		||||
    following: $js{"friends_count"}.getInt,
 | 
			
		||||
    followers: $js{"followers_count"}.getInt,
 | 
			
		||||
    tweets: $js{"statuses_count"}.getInt,
 | 
			
		||||
    likes: $js{"favourites_count"}.getInt,
 | 
			
		||||
    media: $js{"media_count"}.getInt,
 | 
			
		||||
    following: js{"friends_count"}.getInt,
 | 
			
		||||
    followers: js{"followers_count"}.getInt,
 | 
			
		||||
    tweets: js{"statuses_count"}.getInt,
 | 
			
		||||
    likes: js{"favourites_count"}.getInt,
 | 
			
		||||
    media: js{"media_count"}.getInt,
 | 
			
		||||
    verified: js{"verified"}.getBool,
 | 
			
		||||
    protected: js{"protected"}.getBool,
 | 
			
		||||
    joinDate: js{"created_at"}.getTime
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -47,6 +47,7 @@ proc initRedisPool*(cfg: Config) {.async.} =
 | 
			
		|||
    await migrate("snappyRss", "rss:*")
 | 
			
		||||
    await migrate("userBuckets", "p:*")
 | 
			
		||||
    await migrate("profileDates", "p:*")
 | 
			
		||||
    await migrate("profileStats", "p:*")
 | 
			
		||||
 | 
			
		||||
    pool.withAcquire(r):
 | 
			
		||||
      # optimize memory usage for profile ID buckets
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -19,8 +19,7 @@ proc timelineRss*(req: Request; cfg: Config; query: Query): Future[Rss] {.async.
 | 
			
		|||
    names = getNames(name)
 | 
			
		||||
 | 
			
		||||
  if names.len == 1:
 | 
			
		||||
    (profile, timeline) =
 | 
			
		||||
      await fetchSingleTimeline(after, query, skipRail=true)
 | 
			
		||||
    (profile, timeline) = await fetchTimeline(after, query, skipRail=true)
 | 
			
		||||
  else:
 | 
			
		||||
    var q = query
 | 
			
		||||
    q.fromUser = names
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -19,8 +19,8 @@ proc getQuery*(request: Request; tab, name: string): Query =
 | 
			
		|||
  of "search": initQuery(params(request), name=name)
 | 
			
		||||
  else: Query(fromUser: @[name])
 | 
			
		||||
 | 
			
		||||
proc fetchSingleTimeline*(after: string; query: Query; skipRail=false):
 | 
			
		||||
                        Future[(Profile, Timeline, PhotoRail)] {.async.} =
 | 
			
		||||
proc fetchTimeline*(after: string; query: Query; skipRail=false):
 | 
			
		||||
                  Future[(Profile, Timeline, PhotoRail)] {.async.} =
 | 
			
		||||
  let name = query.fromUser[0]
 | 
			
		||||
 | 
			
		||||
  var
 | 
			
		||||
| 
						 | 
				
			
			@ -86,7 +86,7 @@ proc showTimeline*(request: Request; query: Query; cfg: Config; prefs: Prefs;
 | 
			
		|||
      html = renderTweetSearch(timeline, prefs, getPath())
 | 
			
		||||
    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.id.len == 0: return
 | 
			
		||||
| 
						 | 
				
			
			@ -139,7 +139,7 @@ proc createTimelineRouter*(cfg: Config) =
 | 
			
		|||
          timeline.beginning = true
 | 
			
		||||
          resp $renderTweetSearch(timeline, prefs, getPath())
 | 
			
		||||
        else:
 | 
			
		||||
          var (_, timeline, _) = await fetchSingleTimeline(after, query, skipRail=true)
 | 
			
		||||
          var (_, timeline, _) = await fetchTimeline(after, query, skipRail=true)
 | 
			
		||||
          if timeline.content.len == 0: resp Http404
 | 
			
		||||
          timeline.beginning = true
 | 
			
		||||
          resp $renderTimelineTweets(timeline, prefs, getPath())
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -48,17 +48,16 @@ type
 | 
			
		|||
    id*: string
 | 
			
		||||
    username*: string
 | 
			
		||||
    fullname*: string
 | 
			
		||||
    lowername*: string
 | 
			
		||||
    location*: string
 | 
			
		||||
    website*: string
 | 
			
		||||
    bio*: string
 | 
			
		||||
    userPic*: string
 | 
			
		||||
    banner*: string
 | 
			
		||||
    following*: string
 | 
			
		||||
    followers*: string
 | 
			
		||||
    tweets*: string
 | 
			
		||||
    likes*: string
 | 
			
		||||
    media*: string
 | 
			
		||||
    following*: int
 | 
			
		||||
    followers*: int
 | 
			
		||||
    tweets*: int
 | 
			
		||||
    likes*: int
 | 
			
		||||
    media*: int
 | 
			
		||||
    verified*: bool
 | 
			
		||||
    protected*: bool
 | 
			
		||||
    suspended*: bool
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -5,12 +5,12 @@ import karax/[karaxdsl, vdom, vstyles]
 | 
			
		|||
import renderutils, search
 | 
			
		||||
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
 | 
			
		||||
  buildHtml(li(class=class)):
 | 
			
		||||
    span(class="profile-stat-header"): text capitalizeAscii(t)
 | 
			
		||||
    span(class="profile-stat-num"):
 | 
			
		||||
      text if num.len == 0: "?" else: insertSep(num, ',')
 | 
			
		||||
      text insertSep($num, ',')
 | 
			
		||||
 | 
			
		||||
proc renderProfileCard*(profile: Profile; prefs: Prefs): VNode =
 | 
			
		||||
  buildHtml(tdiv(class="profile-card")):
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
		Reference in New Issue