-
Notifications
You must be signed in to change notification settings - Fork 638
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix #586 hubot-slack calling bots.info a suspicious number of times #588
Conversation
Codecov Report
@@ Coverage Diff @@
## master #588 +/- ##
==========================================
- Coverage 85.03% 84.93% -0.11%
==========================================
Files 6 6
Lines 381 385 +4
Branches 85 85
==========================================
+ Hits 324 327 +3
- Misses 33 34 +1
Partials 24 24
Continue to review full report at Codecov.
|
fetches.item_user = @fetchUser event.item_user if event.item_user | ||
if event.bot_id | ||
fetches.bot = @fetchBotUser event.bot_id | ||
else if event.user |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
with this change, when the event has a bot_id
we will not make a call to Web API method users.info
, and therefore there won't be a value for fetched.user
later.
this seems safe because there's no place in the branch of code where fetched.bot
is assigned, that the value of fetched.user
is used. 👍
but i am wondering, how will this reduce the number of calls to bots.info
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
but i am wondering, how will this reduce the number of calls to bots.info?
The root cause of the increase of bots.info
calls is lack of the timing to run the following lines with the latest payloads.
- https://github.com/seratch/hubot-slack/blob/0a063513c4a8c7b53d6481d1b41d35f58622e208/src/client.coffee#L367
- https://github.com/seratch/hubot-slack/blob/0a063513c4a8c7b53d6481d1b41d35f58622e208/src/client.coffee#L372
The combination of the latest payloads and current SlackClient
implementation keeps the @botUserIdMap
empty in any case. So, fetchBotUser
method calls bots.info
API every time receiving an event with both bot_id
and user
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ohhh i see! So now that event.user
is in every bot message, fetched.user
always has a value, and then botUserIdMap
is never updated. This change makes it so fetched.user
will not have a value when both event.bot
and event.user
are present. 👍
Let me know when you'd like me to test this! |
@mistydemeo Thanks a lot for your help on this! I just released version 4.7.2. Could you try it out when you have a chance? |
I've deployed 4.7.2, and it's behaving normally. We deployed at 11:15 PDT; can you please take a look at our API usage and see if it's reduced since then? |
@mistydemeo Thank you! After your deployment, we're seeing the significant decrease in |
Summary
This pull request fixes #586 by changing the internals of
SlackClient
a bit.The latest RTM event payloads from Slack has both
user
andbot_id
even for events generated by a bot user as below:In such cases,
SlackClient
's@botUserIdMap
(the internal memory cache of bot user information) is not updated. That's the reason why the cache doesn't work as expected and a large number ofbots.info
calls may occur when receiving bot user events.Requirements (place an
x
in each[ ]
)