Skip to content

Commit

Permalink
Add console.time to getUserInfo and getTweetInfo (#51)
Browse files Browse the repository at this point in the history
* Add console.time to getUserInfo and getTweetInfo

* No need to measure time in getUserInfo

* Strings must use single quotes

* Add console.timeEnd to catch{} block

* Add Math.random() to constant string

* Remove unnecessary console.log
  • Loading branch information
davideluque authored Aug 10, 2020
1 parent 1312432 commit 5c866d0
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion src/calculator/service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -156,12 +156,20 @@ async function getUserInfo(userId: string) : Promise<TwitterUser> {
}

async function getTweetInfo(tweetId: string) : Promise<Tweet> {
const client = buildTwitClient()
const DEBUG_TWEET_TWITTER_API_TIME_LABEL = 'Time spent calling the Twitter API\
to get tweet info - ' + Math.random()

console.time(DEBUG_TWEET_TWITTER_API_TIME_LABEL)
const client = buildTwitClient()

try {
const response = await client.get('statuses/show', { id: tweetId, tweet_mode: 'extended' })
console.timeEnd(DEBUG_TWEET_TWITTER_API_TIME_LABEL)

return responseToTweet(response.data)
} catch (e) {
console.log(e)
console.timeEnd(DEBUG_TWEET_TWITTER_API_TIME_LABEL)
throw e
}
}
Expand Down

0 comments on commit 5c866d0

Please sign in to comment.