1
0
mirror of https://github.com/zedeus/nitter synced 2024-11-23 02:16:32 +01:00

Improve memory usage by making Thread a ref object

This commit is contained in:
Zed 2019-07-03 07:18:19 +02:00
parent 640bb2fadf
commit 92e3df411f
4 changed files with 7 additions and 4 deletions

View File

@ -110,6 +110,7 @@ proc getVideo*(tweet: Tweet; token: string) {.async.} =
tokenUses.inc
proc getVideos*(thread: Thread; token="") {.async.} =
if thread == nil: return
var gToken = token
if gToken.len == 0:
@ -150,6 +151,7 @@ proc getPoll*(tweet: Tweet) {.async.} =
tweet.poll = some(parsePoll(html))
proc getPolls*(thread: Thread) {.async.} =
if thread == nil: return
var polls = thread.tweets.filterIt(it.poll.isSome)
await all(polls.map(getPoll))

View File

@ -88,6 +88,7 @@ proc parseTweet*(node: XmlNode): Tweet =
proc parseThread*(nodes: XmlNode): Thread =
if nodes == nil: return
result = Thread()
for n in nodes.filterIt(it.kind != xnText):
let class = n.attr("class").toLower()
if "tombstone" in class or "unavailable" in class:

View File

@ -91,7 +91,7 @@ type
photos*: seq[string]
poll*: Option[Poll]
Thread* = object
Thread* = ref object
tweets*: seq[Tweet]
more*: int

View File

@ -104,7 +104,7 @@
#proc renderConversation*(conversation: Conversation): string =
<div class="conversation" id="tweets">
<div class="main-thread">
#if conversation.before.tweets.len > 0:
#if conversation.before != nil:
<div class="before-tweet thread-line">
#for i, tweet in conversation.before.tweets:
${renderTweet(tweet, first=(i == 0))}
@ -112,10 +112,10 @@
</div>
#end if
<div class="main-tweet">
#let afterClass = if conversation.after.tweets.len > 0: "thread thread-line" else: ""
#let afterClass = if conversation.after != nil: "thread thread-line" else: ""
${renderTweet(conversation.tweet, class=afterClass)}
</div>
#if conversation.after.tweets.len > 0:
#if conversation.after != nil:
<div class="after-tweet thread-line">
#for i, tweet in conversation.after.tweets:
${renderTweet(tweet, first=(i == 0), last=(i == conversation.after.tweets.high))}