adding func for finding channels with too many messages

This commit is contained in:
shockrah 2020-08-23 17:47:25 -07:00
parent 434e5a91ad
commit 981bd6fcf7

View File

@ -12,33 +12,46 @@ CONFIG = {
'port': int(getenv('DATABASE_PORT')),
}
def add_message_limit(limit: int):
def purge_clamped_messages(cursor, channels: list, limit: int):
pass
def message_limit(limit: int):
count_query = '''
SELECT channel_name, COUNT(time) FROM messages
GROUP BY channel_name;
'''
conn = sql.connect(**CONFIG)
cursor = conn.cursor()
cursor = conn.cursor(prepared=True)
cursor.execute(count_query,())
# figure out which channels need pruning
for i in cursor:
print(i)
# collect the channels that require filtering
channels = list(filter((None).__ne__, [limit if chan[1] > limit else None for chan in cursor]))
if len(channels) > 0:
purge_clamped_messages(cursor, channels, limit)
else:
print(f'[ {__file__} ] : No messages to remove from clamped set')
cursor.close()
conn.close()
def add_message_timeout():
pass
def rm_message_limit():
pass
def rm_message_timeout():
def message_timeout():
pass
if __name__ == '__main__':
parser = argparse.ArgumentParser(
description='An optional microservice for freechat to make the messaging system more transient'
description='A script which can be setup as a chronjob to make messaging'
' similar to how image boards clean up threads'
)
parser.add_argument('-t', '--time-out', type=float, required=False)
parser.add_argument('-m', '--message-limit', type=int, required=False)
parser.add_argument('-r', '--remove' type=string, required=False, choices=['timeout', 'limit'])
args = vars(parser.parse_args())
@ -47,12 +60,6 @@ if __name__ == '__main__':
timeout = args['time_out']
# timeout is given in days 30 => 30 day time limit
if limit: add_message_limit(limit)
if timeout: add_message_timeout(timeout)
if limit: message_limit(limit)
if timeout: message_timeout(timeout)
if args['remove']:
remove_opts = {
'timeout': rm_message_timeout,
'limit': rm_message_limit,
}
remove_opts[f]()