diff --git a/inyoka/default_settings.py b/inyoka/default_settings.py index 1a793cfdf..72d2ca77b 100644 --- a/inyoka/default_settings.py +++ b/inyoka/default_settings.py @@ -8,14 +8,13 @@ :license: BSD, see LICENSE for more details. """ from collections import OrderedDict - -import jinja2 from datetime import timedelta from os.path import dirname, join from celery.schedules import crontab import inyoka +import jinja2 gettext_noop = lambda x: x @@ -159,6 +158,11 @@ # days to describe an inactive user USER_INACTIVE_DAYS = 365 +# days after private messages +# in specific folder will be removed +PRIVATE_MESSAGE_TRASH_DURATION = 90 +PRIVATE_MESSAGE_INBOX_SENT_DURATION = 180 + # wiki settings WIKI_MAIN_PAGE = 'Welcome' @@ -315,6 +319,10 @@ 'render_all_wiki_pages': { 'task': 'inyoka.wiki.tasks.render_all_pages', 'schedule': crontab(hour=23, minute=5), + }, + 'clean_private_message_folders': { + 'task': 'inyoka.portal.tasks.clean_privmsg_folders', + 'schedule': crontab(hour=6, minute=30, day_of_week='saturday'), } } diff --git a/inyoka/portal/tasks.py b/inyoka/portal/tasks.py index 2165eabcc..2c38f44f4 100644 --- a/inyoka/portal/tasks.py +++ b/inyoka/portal/tasks.py @@ -15,6 +15,7 @@ from django.core.cache import cache from django.db import connection +from inyoka.portal.models import PrivateMessageEntry from inyoka.portal.user import User from inyoka.utils.logger import logger from inyoka.utils.storage import storage @@ -78,3 +79,25 @@ def query_counter_task(cache_key, sql): cursor = connection.cursor() cursor.execute(sql) cache.set(cache_key, cursor.fetchone()[0]) + + +@shared_task +def clean_privmsg_folders(): + """ + Remove all messages in private message folders (except 'archive') + after end of cache duration according to settings + has been reached. + """ + privmsgs_trash = PrivateMessageEntry.objects.filter( + folder="2", + message__pub_date__lte=datetime.now() - timedelta( + days=settings.PRIVATE_MESSAGE_TRASH_DURATION), + ) + privmsgs_inbox_sent = PrivateMessageEntry.objects.filter( + folder__in=["0", "1"], + message__pub_date__lte=datetime.now() - timedelta( + days=settings.PRIVATE_MESSAGE_INBOX_SENT_DURATION), + ) + logger.info("Deleting private messages after end of cache duration") + privmsgs_trash.delete() + privmsgs_inbox_sent.delete()