diff options
Diffstat (limited to 'askbot/management')
-rw-r--r-- | askbot/management/commands/clean_session.py | 9 |
1 files changed, 9 insertions, 0 deletions
diff --git a/askbot/management/commands/clean_session.py b/askbot/management/commands/clean_session.py index 6800420b..2e663b22 100644 --- a/askbot/management/commands/clean_session.py +++ b/askbot/management/commands/clean_session.py @@ -3,10 +3,13 @@ works only when sessions are stored in the database """ from django.core.management.base import NoArgsCommand from django.contrib.sessions.models import Session +from django.db import transaction from optparse import make_option from askbot.utils.console import ProgressBar from datetime import datetime +ITEMS_PER_TRANSACTION = 1000 + class Command(NoArgsCommand): """Django management command class""" @@ -19,6 +22,7 @@ class Command(NoArgsCommand): ), ) + @transaction.commit_manually def handle_noargs(self, **options): """deletes old sessions""" quiet = options.get('quiet', False) @@ -32,6 +36,11 @@ class Command(NoArgsCommand): message = 'There are %d expired sessions' % count expired_sessions = ProgressBar(expired_sessions, count, message) + deleted_count = 0 for session in expired_sessions: session.delete() + deleted_count += 1 + if deleted_count % ITEMS_PER_TRANSACTION == 0: + transaction.commit() + transaction.commit() |