@@ -187,13 +187,21 @@ impl ApiCache {
187
187
}
188
188
}
189
189
// end of inner loop
190
- // the event processing is now done, so process a single guild
190
+ // the event processing is now done, so process guilds until none are expired in a "work loop"
191
191
192
192
let mut now = SimpleTime :: UNIX_EPOCH ; // initialize it to some arbitrary default: we set it later.
193
193
let mut work_remaining = true ;
194
+ let mut touched_guild_set =
195
+ HashSet :: with_hasher ( ahash:: RandomState :: default ( ) ) ;
194
196
while work_remaining {
195
197
// find the first guild that needs a refresh. This is a simple queue pop.
196
198
if let Some ( mut queue_entry) = queue. pop ( ) {
199
+ // if the queue is now empty no reason to go again
200
+ work_remaining &= !queue. is_empty ( ) ;
201
+
202
+ // record that we've touched this guild ID in the work loop
203
+ touched_guild_set. insert ( queue_entry. guild_id ) ;
204
+
197
205
// grab the current time: we'll need it a couple of times and I want it to keep the same reading
198
206
now = SimpleTime :: now ( ) ;
199
207
@@ -338,23 +346,27 @@ impl ApiCache {
338
346
339
347
if guild_valid {
340
348
// done loading the guild; time to put it back in the queue
341
- let previous_guild_id = queue_entry. guild_id ;
342
349
queue. push ( queue_entry) ;
343
- let next_guild_id = queue
344
- . peek ( )
345
- . expect (
346
- "queue should not be empty immediately after push" ,
347
- )
348
- . guild_id ;
349
-
350
- // if the new head of the queue is different, then go again
351
- work_remaining = previous_guild_id != next_guild_id;
350
+
351
+ // check if we want to enter the work loop again
352
+ if work_remaining {
353
+ let next_guild_id = queue
354
+ . peek ( )
355
+ . expect (
356
+ "queue should not be empty immediately after push" ,
357
+ )
358
+ . guild_id ;
359
+
360
+ // if we haven't touched the next guild ID yet, then go again
361
+ work_remaining &=
362
+ !touched_guild_set. contains ( & next_guild_id) ;
363
+ }
352
364
} else {
353
365
// something about the guild was screwed up so we're just going to unregister it
354
366
guild_set. remove ( & queue_entry. guild_id ) ;
355
367
}
356
368
}
357
- }
369
+ } // end work loop
358
370
359
371
// update the sleep time
360
372
if let Some ( next_queue_entry) = queue. peek ( ) {
0 commit comments