Skip to content

Commit 009255f

Browse files
authored
Avoid extra Guild removals in Ready handler (#3331)
This code was removing guilds from cache which the current shard is responsible for, but wasn't received in the unavailable payload. This code path could only be hit under extreme circumstances, such as unsuccessful resumes, and since we cannot rely on cache consistency after an unsuccessful resume anyway this does more bad than good. To add to the motivation for doing this, out of the libraries checked (twilight, discord.py, hikari) none do this either.
1 parent bf2b2ff commit 009255f

File tree

1 file changed

+0
-21
lines changed

1 file changed

+0
-21
lines changed

src/cache/event.rs

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
use std::collections::HashSet;
2-
31
use super::{Cache, CacheUpdate};
42
use crate::model::channel::{GuildChannel, Message};
53
use crate::model::event::{
@@ -474,27 +472,8 @@ impl CacheUpdate for ReadyEvent {
474472
cache.unavailable_guilds.insert(unavailable.id, ());
475473
}
476474

477-
// We may be removed from some guilds between disconnect and ready, so handle that.
478-
let mut guilds_to_remove = vec![];
479-
let ready_guilds_hashset =
480-
self.ready.guilds.iter().map(|status| status.id).collect::<HashSet<_>>();
481475
let shard_data = self.ready.shard.unwrap_or_else(|| ShardInfo::new(ShardId(1), 1));
482476

483-
for guild_entry in cache.guilds.iter() {
484-
let guild = guild_entry.key();
485-
// Only handle data for our shard.
486-
if crate::utils::shard_id(*guild, shard_data.total) == shard_data.id.0
487-
&& !ready_guilds_hashset.contains(guild)
488-
{
489-
guilds_to_remove.push(*guild);
490-
}
491-
}
492-
if !guilds_to_remove.is_empty() {
493-
for guild in guilds_to_remove {
494-
cache.guilds.remove(&guild);
495-
}
496-
}
497-
498477
{
499478
let mut cached_shard_data = cache.shard_data.write();
500479
cached_shard_data.total = shard_data.total;

0 commit comments

Comments
 (0)