from django.core.management.base import NoArgsCommand
from django.conf import settings
from django import db
"""With InnoDB, the naive DELETE query will completly lock the
session table even for reads and the session table will become unusable.
This script is a workaround that will first select a certain
amount of sessions and then delete them by ID. This will not lock
the entire table but only the selected sessions."""
help = "Cleanup the sessions table without locking the whole table."
from django.contrib.sessions.models import Session
print "Searching for old sessions..."
print "SQL query for %d sessions" % SESSION_DELETE_BULK_SIZE
sessions = .
if not :
print " ¦- found %d sessions." %
print " `- all deleted."