Usiel opened a new pull request, #32585: URL: https://github.com/apache/superset/pull/32585
### SUMMARY Adds a celery task to warm up the Slack channel cache and allows admins to schedule the same task (with example). This is helpful for cases where retrieval of the full channel list takes minutes. #### Changes to the `get_channels` function The Slack conversations API is not necessarily faster when using the `types` filter: For example, when we filter for private channels, the cursor will still iterate over all public channels and the number of requests remains the same, only the data transmitted is less. With this in mind, I believe it is more efficient for us to cache only a single value for `get_channels()` and avoid having multiple cache values for each possible value of `types`. Doing the filtering in `get_channels_with_search` on demand doesn't add much cost. Additionally, the `limit` param is also not relevant for the cache key and is inlined. ... and, of course, this change makes the celery task more sensible :) #### Warning There is a minor API change in this PR: Previously, we followed Slack's [conversations.list](https://api.slack.com/methods/conversations.list) convention, where empty an `types` param means that only public channels are returned. After this PR we will return all channel types when `types` is empty or null. To me that feels more logical, but if people feel we should stick to previous approach I'm OK with changing this. ### TESTING INSTRUCTIONS Pre: - Set `SLACK_API_TOKEN` - Enable `ALERT_REPORTS` #### Test Celery Task ``` celery --app=superset.tasks.celery_app:app call slack.cache_channels ``` **Expected**: Task is launched and result is cached. #### Test Beat Schedule Example 1. Uncomment the beat schedule entry for `slack.cache_channels` 2. [Optional]: Adapt schedule to trigger every minute (or set time) **Expected**: Task is scheduled and result is cached. #### Test REST API Try for `TYPES={"public_channel", "private_channel", "", "public_channel, private_channel"}` ``` curl -X 'GET' \ 'http://localhost:8088/api/v1/report/slack_channels/?q=(types%3A!(<TYPES>))' \ -H 'accept: application/json' \ -H 'Authorization: Bearer <TOKEN>' ``` **Expected**: Cached value is used, filtered and returned. ### ADDITIONAL INFORMATION <!--- Check any relevant boxes with "x" --> <!--- HINT: Include "Fixes #nnn" if you are fixing an existing issue --> - [x] Has associated issue: https://github.com/apache/superset/issues/32480 - [ ] Required feature flags: - [ ] Changes UI - [ ] Includes DB Migration (follow approval process in [SIP-59](https://github.com/apache/superset/issues/13351)) - [ ] Migration is atomic, supports rollback & is backwards-compatible - [ ] Confirm DB migration upgrade and downgrade tested - [ ] Runtime estimates and downtime expectations provided - [ ] Introduces new feature or API - [ ] Removes existing feature or API cc @Vitor-Avila since this builds on your recent work in https://github.com/apache/superset/pull/32529 -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
