Added queue clearing out of messages and periodic DB cleanup for old entries

This commit is contained in:
Frisk 2020-11-09 14:58:05 +01:00
parent baa8eeead9
commit fac70ba7a4
No known key found for this signature in database
GPG key ID: 213F7C15068AF8AC
2 changed files with 7 additions and 8 deletions

View file

@ -50,10 +50,9 @@ class MessageQueue:
def delete_all_with_matching_metadata(self, **properties):
"""Deletes all of the messages that have matching metadata properties (useful for message redaction)"""
for message in messagequeue:
if self.compare_message_to_dict(message[1], properties):
# TODO Delete messages from the queue
raise NotImplemented
for index, item in reversed(list(enumerate(self._queue))):
if self.compare_message_to_dict(item[1], properties):
self._queue.pop(index)
def resend_msgs(self):
if self._queue:

View file

@ -52,12 +52,12 @@ def add_entry(pageid: int, revid: int, logid: int, message):
def clean_entries():
"""Cleans entries that are 50+"""
cleanup = db_cursor.execute(
"SELECT message_id FROM messages WHERE message_id NOT IN (SELECT message_id FROM messages ORDER BY message_id asc LIMIT 50);")
"SELECT message_id FROM messages WHERE message_id NOT IN (SELECT message_id FROM messages ORDER BY message_id desc LIMIT 50);")
for row in cleanup:
db_cursor.execute("DELETE FROM messages WHERE message_id = ?", (cleanup[0]))
cleanup = db_cursor.execute("SELECT msg_id FROM event WHERE msg_id NOT IN (SELECT msg_id FROM event ORDER BY msg_id asc LIMIT 50);")
db_cursor.execute("DELETE FROM messages WHERE message_id = ?", (row[0]))
cleanup = db_cursor.execute("SELECT msg_id FROM event WHERE msg_id NOT IN (SELECT msg_id FROM event ORDER BY msg_id desc LIMIT 50);")
for row in cleanup:
db_cursor.execute("DELETE FROM event WHERE msg_id = ?", (cleanup[0]))
db_cursor.execute("DELETE FROM event WHERE msg_id = ?", (row[0]))
db_connection.commit()
db_connection, db_cursor = create_connection()