Skip to content

Commit

Permalink
Use faster API to get pinned tweets
Browse files Browse the repository at this point in the history
  • Loading branch information
zedeus committed Jan 23, 2022
1 parent 51ae076 commit 27183f1
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 3 deletions.
4 changes: 4 additions & 0 deletions src/api.nim
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,10 @@ proc getTweet*(id: string; after=""): Future[Conversation] {.async.} =
if after.len > 0:
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.} =
let client = newAsyncHttpClient(maxRedirects=0)
try:
Expand Down
1 change: 1 addition & 0 deletions src/consts.nim
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ const

userShow* = api / "1.1/users/show.json"
photoRail* = api / "1.1/statuses/media_timeline.json"
status* = api / "1.1/statuses/show"
search* = api / "2/search/adaptive.json"

timelineApi = api / "2/timeline"
Expand Down
5 changes: 5 additions & 0 deletions src/parser.nim
Original file line number Diff line number Diff line change
Expand Up @@ -372,6 +372,11 @@ proc parseConversation*(js: JsonNode; tweetId: string): Conversation =
elif "cursor-bottom" in entry:
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) =
if js.kind != JArray or js.len == 0:
return
Expand Down
5 changes: 2 additions & 3 deletions src/redis_cache.nim
Original file line number Diff line number Diff line change
Expand Up @@ -151,9 +151,8 @@ proc getCachedTweet*(id: int64): Future[Tweet] {.async.} =
if tweet != redisNil:
tweet.deserialize(Tweet)
else:
let conv = await getTweet($id)
if not conv.isNil:
result = conv.tweet
result = await getStatus($id)
if result.isNil:
await cache(result)

proc getCachedPhotoRail*(name: string): Future[PhotoRail] {.async.} =
Expand Down
1 change: 1 addition & 0 deletions src/types.nim
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ type
listBySlug
listMembers
userRestId
status

RateLimit* = object
remaining*: int
Expand Down

0 comments on commit 27183f1

Please sign in to comment.