Skip to content

Commit

Permalink
pain
Browse files Browse the repository at this point in the history
  • Loading branch information
omame committed Jun 11, 2021
1 parent 471371d commit 4782ea7
Showing 1 changed file with 19 additions and 4 deletions.
23 changes: 19 additions & 4 deletions cogs/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,21 +56,36 @@ def save_data(self):
@tasks.loop(minutes=1.0)
async def periodic_data_clean_and_save(self):
self.logger.debug("cleaning data...")
removed = 0
removed_questions = 0
removed_responses = 0
while len(self.question_map.values()) > self.config["question_limit"]:
self.question_map.pop(list(self.question_map.keys())[0])
removed += 1
removed_questions += 1
to_pop = []
for question_key in self.question_map.keys():
question = self.question_map[question_key]
if question.author in self.config["blacklist"]:
to_pop.append(question_key)
return

responses_to_remove = []
for response in question.responses:
if response.author in self.config["blacklist"]:
responses_to_remove.append(response)

for index in responses_to_remove:
question.responses.remove(index)

removed_responses += len(responses_to_remove)

if len(question.responses) == 0:
to_pop.append(question_key)

for key in to_pop:
self.question_map.pop(key)

removed += len(to_pop)
self.logger.debug("removed %d questions, saving data...", removed)
removed_questions += len(to_pop)
self.logger.debug("removed %d questions and %d responses, saving data...", removed_questions, removed_responses)
self.save_data()

@tasks.loop(minutes=1.0)
Expand Down

0 comments on commit 4782ea7

Please sign in to comment.