mirror of
https://github.com/zedeus/nitter
synced 2024-11-22 09:57:16 +01:00
Optimize timeline data structure
This commit is contained in:
parent
0bc3c153d9
commit
b290f6fd29
@ -486,7 +486,7 @@ proc parseGraphTimeline*(js: JsonNode; root: string; after=""): Profile =
|
|||||||
result.tweets.content.add tweet
|
result.tweets.content.add tweet
|
||||||
elif "-conversation-" in entryId or entryId.startsWith("homeConversation"):
|
elif "-conversation-" in entryId or entryId.startsWith("homeConversation"):
|
||||||
let (thread, self) = parseGraphThread(e)
|
let (thread, self) = parseGraphThread(e)
|
||||||
result.tweets.content.add thread
|
result.tweets.content.add thread.content
|
||||||
elif entryId.startsWith("cursor-bottom"):
|
elif entryId.startsWith("cursor-bottom"):
|
||||||
result.tweets.bottom = e{"content", "value"}.getStr
|
result.tweets.bottom = e{"content", "value"}.getStr
|
||||||
if after.len == 0 and i{"__typename"}.getStr == "TimelinePinEntry":
|
if after.len == 0 and i{"__typename"}.getStr == "TimelinePinEntry":
|
||||||
|
@ -56,9 +56,7 @@ proc fetchProfile*(after: string; query: Query; skipRail=false;
|
|||||||
of posts: await getGraphUserTweets(userId, TimelineKind.tweets, after)
|
of posts: await getGraphUserTweets(userId, TimelineKind.tweets, after)
|
||||||
of replies: await getGraphUserTweets(userId, TimelineKind.replies, after)
|
of replies: await getGraphUserTweets(userId, TimelineKind.replies, after)
|
||||||
of media: await getGraphUserTweets(userId, TimelineKind.media, after)
|
of media: await getGraphUserTweets(userId, TimelineKind.media, after)
|
||||||
else: Profile(tweets: Timeline(beginning: true, content: @[Chain(content:
|
else: Profile(tweets: Timeline(beginning: true, content: @[@[Tweet(tombstone: "Tweet search is unavailable for now")]]))
|
||||||
@[Tweet(tombstone: "Tweet search is unavailable for now")]
|
|
||||||
)]))
|
|
||||||
# else: await getGraphSearch(query, after)
|
# else: await getGraphSearch(query, after)
|
||||||
|
|
||||||
result.user = await user
|
result.user = await user
|
||||||
@ -74,9 +72,7 @@ proc showTimeline*(request: Request; query: Query; cfg: Config; prefs: Prefs;
|
|||||||
if query.fromUser.len != 1:
|
if query.fromUser.len != 1:
|
||||||
let
|
let
|
||||||
# timeline = await getGraphSearch(query, after)
|
# timeline = await getGraphSearch(query, after)
|
||||||
timeline = Profile(tweets: Timeline(beginning: true, content: @[Chain(content:
|
timeline = Profile(tweets: Timeline(beginning: true, content: @[@[Tweet(tombstone: "This features is unavailable for now")]]))
|
||||||
@[Tweet(tombstone: "This features is unavailable for now")]
|
|
||||||
)]))
|
|
||||||
html = renderTweetSearch(timeline.tweets, prefs, getPath())
|
html = renderTweetSearch(timeline.tweets, prefs, getPath())
|
||||||
return renderMain(html, request, cfg, prefs, "Multi", rss=rss)
|
return renderMain(html, request, cfg, prefs, "Multi", rss=rss)
|
||||||
|
|
||||||
|
@ -205,6 +205,8 @@ type
|
|||||||
video*: Option[Video]
|
video*: Option[Video]
|
||||||
photos*: seq[string]
|
photos*: seq[string]
|
||||||
|
|
||||||
|
Tweets* = seq[Tweet]
|
||||||
|
|
||||||
Result*[T] = object
|
Result*[T] = object
|
||||||
content*: seq[T]
|
content*: seq[T]
|
||||||
top*, bottom*: string
|
top*, bottom*: string
|
||||||
@ -212,7 +214,7 @@ type
|
|||||||
query*: Query
|
query*: Query
|
||||||
|
|
||||||
Chain* = object
|
Chain* = object
|
||||||
content*: seq[Tweet]
|
content*: Tweets
|
||||||
hasMore*: bool
|
hasMore*: bool
|
||||||
cursor*: string
|
cursor*: string
|
||||||
|
|
||||||
@ -222,7 +224,7 @@ type
|
|||||||
after*: Chain
|
after*: Chain
|
||||||
replies*: Result[Chain]
|
replies*: Result[Chain]
|
||||||
|
|
||||||
Timeline* = Result[Chain]
|
Timeline* = Result[Tweets]
|
||||||
|
|
||||||
Profile* = object
|
Profile* = object
|
||||||
user*: User
|
user*: User
|
||||||
@ -275,5 +277,5 @@ type
|
|||||||
proc contains*(thread: Chain; tweet: Tweet): bool =
|
proc contains*(thread: Chain; tweet: Tweet): bool =
|
||||||
thread.content.anyIt(it.id == tweet.id)
|
thread.content.anyIt(it.id == tweet.id)
|
||||||
|
|
||||||
proc add*(timeline: var seq[Chain]; tweet: Tweet) =
|
proc add*(timeline: var seq[Tweets]; tweet: Tweet) =
|
||||||
timeline.add Chain(content: @[tweet])
|
timeline.add @[tweet]
|
||||||
|
@ -56,16 +56,16 @@ Twitter feed for: ${desc}. Generated by ${cfg.hostname}
|
|||||||
#end if
|
#end if
|
||||||
#end proc
|
#end proc
|
||||||
#
|
#
|
||||||
#proc renderRssTweets(tweets: seq[Chain]; cfg: Config; userId=""): string =
|
#proc renderRssTweets(tweets: seq[Tweets]; cfg: Config; userId=""): string =
|
||||||
#let urlPrefix = getUrlPrefix(cfg)
|
#let urlPrefix = getUrlPrefix(cfg)
|
||||||
#var links: seq[string]
|
#var links: seq[string]
|
||||||
#for c in tweets:
|
#for thread in tweets:
|
||||||
# for t in c.content:
|
# for tweet in thread:
|
||||||
# if userId.len > 0 and t.user.id != userId: continue
|
# if userId.len > 0 and tweet.user.id != userId: continue
|
||||||
# end if
|
# end if
|
||||||
#
|
#
|
||||||
# let retweet = if t.retweet.isSome: t.user.username else: ""
|
# let retweet = if tweet.retweet.isSome: tweet.user.username else: ""
|
||||||
# let tweet = if retweet.len > 0: t.retweet.get else: t
|
# let tweet = if retweet.len > 0: tweet.retweet.get else: tweet
|
||||||
# let link = getLink(tweet)
|
# let link = getLink(tweet)
|
||||||
# if link in links: continue
|
# if link in links: continue
|
||||||
# end if
|
# end if
|
||||||
@ -113,7 +113,7 @@ ${renderRssTweets(profile.tweets.content, cfg, userId=profile.user.id)}
|
|||||||
</rss>
|
</rss>
|
||||||
#end proc
|
#end proc
|
||||||
#
|
#
|
||||||
#proc renderListRss*(tweets: seq[Chain]; list: List; cfg: Config): string =
|
#proc renderListRss*(tweets: seq[Tweets]; list: List; cfg: Config): string =
|
||||||
#let link = &"{getUrlPrefix(cfg)}/i/lists/{list.id}"
|
#let link = &"{getUrlPrefix(cfg)}/i/lists/{list.id}"
|
||||||
#result = ""
|
#result = ""
|
||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
@ -130,7 +130,7 @@ ${renderRssTweets(tweets, cfg)}
|
|||||||
</rss>
|
</rss>
|
||||||
#end proc
|
#end proc
|
||||||
#
|
#
|
||||||
#proc renderSearchRss*(tweets: seq[Chain]; name, param: string; cfg: Config): string =
|
#proc renderSearchRss*(tweets: seq[Tweets]; name, param: string; cfg: Config): string =
|
||||||
#let link = &"{getUrlPrefix(cfg)}/search"
|
#let link = &"{getUrlPrefix(cfg)}/search"
|
||||||
#let escName = xmltree.escape(name)
|
#let escName = xmltree.escape(name)
|
||||||
#result = ""
|
#result = ""
|
||||||
|
@ -39,7 +39,7 @@ proc renderNoneFound(): VNode =
|
|||||||
h2(class="timeline-none"):
|
h2(class="timeline-none"):
|
||||||
text "No items found"
|
text "No items found"
|
||||||
|
|
||||||
proc renderThread(thread: seq[Tweet]; prefs: Prefs; path: string): VNode =
|
proc renderThread(thread: Tweets; prefs: Prefs; path: string): VNode =
|
||||||
buildHtml(tdiv(class="thread-line")):
|
buildHtml(tdiv(class="thread-line")):
|
||||||
let sortedThread = thread.sortedByIt(it.id)
|
let sortedThread = thread.sortedByIt(it.id)
|
||||||
for i, tweet in sortedThread:
|
for i, tweet in sortedThread:
|
||||||
@ -106,9 +106,9 @@ proc renderTimelineTweets*(results: Timeline; prefs: Prefs; path: string;
|
|||||||
var retweets: seq[int64]
|
var retweets: seq[int64]
|
||||||
|
|
||||||
for thread in results.content:
|
for thread in results.content:
|
||||||
if thread.content.len == 1:
|
if thread.len == 1:
|
||||||
let
|
let
|
||||||
tweet = thread.content[0]
|
tweet = thread[0]
|
||||||
retweetId = if tweet.retweet.isSome: get(tweet.retweet).id else: 0
|
retweetId = if tweet.retweet.isSome: get(tweet.retweet).id else: 0
|
||||||
|
|
||||||
if retweetId in retweets or tweet.id in retweets or
|
if retweetId in retweets or tweet.id in retweets or
|
||||||
@ -121,7 +121,7 @@ proc renderTimelineTweets*(results: Timeline; prefs: Prefs; path: string;
|
|||||||
hasThread = get(tweet.retweet).hasThread
|
hasThread = get(tweet.retweet).hasThread
|
||||||
renderTweet(tweet, prefs, path, showThread=hasThread)
|
renderTweet(tweet, prefs, path, showThread=hasThread)
|
||||||
else:
|
else:
|
||||||
renderThread(thread.content, prefs, path)
|
renderThread(thread, prefs, path)
|
||||||
|
|
||||||
if results.bottom.len > 0:
|
if results.bottom.len > 0:
|
||||||
renderMore(results.query, results.bottom)
|
renderMore(results.query, results.bottom)
|
||||||
|
Loading…
Reference in New Issue
Block a user