Skip to content

Add persistence to the help channel system#987

Merged
kosayoda merged 16 commits into
masterfrom
help_channel_rediscache
Jun 16, 2020
Merged

Add persistence to the help channel system#987
kosayoda merged 16 commits into
masterfrom
help_channel_rediscache

Conversation

@lemonsaurus
Copy link
Copy Markdown
Contributor

This PR should ensure that help channel-related data is persisted across bot restarts.

To achieve this, we make two changes.

RedisCache now supports Booleans as values

For the unanswered cache, we need to know whether or not a channel has been answered, and so it was relevant to store a boolean in the RedisCache. There was no support for this, so I added some. It seems like a feature we might want in the future for other things anyway.

Refactoring help_channels.py

The rest is pretty straight forward - Replacing the help_channel_claimants, unanswered, and claim_times dicts with RedisCaches, and changing the code that accessed it to do so in a RedisCache compatible way.

Leon Sandøy added 2 commits May 31, 2020 19:17
We're gonna need this for the help channel handling, and it seems like a
reasonable type to support anyway. It requires a tiny bit of special
handling, but nothing outrageous.
More specifically, we're turning three
dicts into RedisCaches:
- help_channel_claimants
- unanswered
- claim_times

These will still work the same way, but will now persist their contents
across restarts.
@lemonsaurus lemonsaurus requested a review from a team as a code owner June 5, 2020 22:58
@lemonsaurus lemonsaurus requested review from jb3 and kosayoda and removed request for a team June 5, 2020 22:58
Comment thread bot/utils/redis_cache.py Outdated
Comment thread bot/cogs/help_channels.py Outdated
Comment thread bot/cogs/help_channels.py Outdated
Comment thread bot/cogs/help_channels.py Outdated
Comment thread bot/cogs/help_channels.py Outdated
Leon Sandøy and others added 11 commits June 6, 2020 11:57
This means we don't need to rely on strtobool, and is a cleaner
implementation overall. Thanks @MarkKoz.
We're also switching from datetime.now() to datetime.utcnow().
Instead of first checking if the channel.id exists and then checking
what it is, we just do a single API call, to prevent cases where
something fucky might happen inbetween the first and the second call.
Since help_channel_claimants.delete will never raise a KeyError, it's
not necessary to suppress one.
The datetime module returns a local timestamp for naïve datetimes.
It has to be timezone-aware to ensure it will always be in UTC.
Future code will also need to get this time, so moving it out to a
separate function reduces redundancy.
Moving this code into a separate function reduces redundancy down the
line. This will also get used to re-scheduled cooldowns after a restart.
Using the cache is more efficient since it can check only the users it
expects to have a cooldown rather than searching all guild members.
Furthermore, re-scheduling the cooldowns ensures members experience the
full duration of the cooldown. Previously, all cooldowns were removed,
regardless of whether they were expired.
Comment thread bot/cogs/help_channels.py Outdated
@MarkKoz
Copy link
Copy Markdown
Contributor

MarkKoz commented Jun 9, 2020

I made a change to use the cache to remove expired cooldowns or re-schedule active cooldowns when the bot restarts. See b49f3e5.

@MarkKoz MarkKoz added the a: help channels Related to the help channel system label Jun 9, 2020
Copy link
Copy Markdown
Contributor

@MarkKoz MarkKoz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice to see the cache being put to use. Excellent work. Only spotted one issue with the timestamps which I fixed myself.

Copy link
Copy Markdown
Contributor

@kosayoda kosayoda left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. Implemented a trivial change suggested by Mark, and updated the docstring for RedisCache to reflect the new boolean type available for values.

@ghost ghost removed the needs 1 approval label Jun 16, 2020
@kosayoda kosayoda merged commit e0bedb6 into master Jun 16, 2020
@kosayoda kosayoda deleted the help_channel_rediscache branch June 16, 2020 12:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

a: help channels Related to the help channel system l: 1 - intermediate p: 1 - high High Priority

Projects

None yet

Development

Successfully merging this pull request may close these issues.

8 participants