monzo / response

Monzo's real-time incident response and reporting tool ⚡️
MIT License
1.53k stars 165 forks source link

Cache CommsChannel channel name #150

Closed milesbxf closed 5 years ago

milesbxf commented 5 years ago

Currently any time that CommsChannel.channel_name is requested, we go and fetch it from the Slack API. This leads to rate limiting issues when listing a large number of incidents, as Response will call the Slack API for every single incident.

This change caches the channel name in a new model field, updating it whenever we get a channel_rename event from Slack. One complication is that we'd like to backfill this for existing CommsChannels in the database (and make the field non-nullable) - I've written a reasonably complex migration that fetches CommsChannel names and populates the field. This has the unfortunate side-effect of requiring a valid SLACK_TOKEN environment variable when running migrations.

TODO: