Use faster API to get pinned tweets

This commit is contained in:
Zed 2022-01-23 07:45:01 +01:00
parent 51ae076ea0
commit 27183f1a74
5 changed files with 13 additions and 3 deletions

View file

@ -114,6 +114,10 @@ proc getTweet*(id: string; after=""): Future[Conversation] {.async.} =
if after.len > 0: if after.len > 0:
result.replies = await getReplies(id, after) result.replies = await getReplies(id, after)
proc getStatus*(id: string): Future[Tweet] {.async.} =
let url = status / (id & ".json") ? genParams()
result = parseStatus(await fetch(url, Api.status))
proc resolve*(url: string; prefs: Prefs): Future[string] {.async.} = proc resolve*(url: string; prefs: Prefs): Future[string] {.async.} =
let client = newAsyncHttpClient(maxRedirects=0) let client = newAsyncHttpClient(maxRedirects=0)
try: try:

View file

@ -9,6 +9,7 @@ const
userShow* = api / "1.1/users/show.json" userShow* = api / "1.1/users/show.json"
photoRail* = api / "1.1/statuses/media_timeline.json" photoRail* = api / "1.1/statuses/media_timeline.json"
status* = api / "1.1/statuses/show"
search* = api / "2/search/adaptive.json" search* = api / "2/search/adaptive.json"
timelineApi = api / "2/timeline" timelineApi = api / "2/timeline"

View file

@ -372,6 +372,11 @@ proc parseConversation*(js: JsonNode; tweetId: string): Conversation =
elif "cursor-bottom" in entry: elif "cursor-bottom" in entry:
result.replies.bottom = e.getCursor result.replies.bottom = e.getCursor
proc parseStatus*(js: JsonNode): Tweet =
result = parseTweet(js)
if not result.isNil:
result.user = parseUser(js{"user"})
proc parseInstructions[T](res: var Result[T]; global: GlobalObjects; js: JsonNode) = proc parseInstructions[T](res: var Result[T]; global: GlobalObjects; js: JsonNode) =
if js.kind != JArray or js.len == 0: if js.kind != JArray or js.len == 0:
return return

View file

@ -151,9 +151,8 @@ proc getCachedTweet*(id: int64): Future[Tweet] {.async.} =
if tweet != redisNil: if tweet != redisNil:
tweet.deserialize(Tweet) tweet.deserialize(Tweet)
else: else:
let conv = await getTweet($id) result = await getStatus($id)
if not conv.isNil: if result.isNil:
result = conv.tweet
await cache(result) await cache(result)
proc getCachedPhotoRail*(name: string): Future[PhotoRail] {.async.} = proc getCachedPhotoRail*(name: string): Future[PhotoRail] {.async.} =

View file

@ -17,6 +17,7 @@ type
listBySlug listBySlug
listMembers listMembers
userRestId userRestId
status
RateLimit* = object RateLimit* = object
remaining*: int remaining*: int