Ticket #4427: daily_cleanup.2.patch

File daily_cleanup.2.patch, 850 bytes (added by nick.lane.au@…, 17 years ago)

Unified diff.

  • django/bin/daily_cleanup.py

     
    77sessions at the moment).
    88"""
    99
    10 import datetime
    11 from django.db import transaction
    12 from django.contrib.sessions.models import Session
    13 
     10from django.db import backend, connection, transaction
    1411
    1512def clean_up():
    16     # Clean up expired sessions.
    17     Session.objects.filter(expire_date__lt=datetime.datetime.now()).delete()
     13    # Clean up old database records
     14    cursor = connection.cursor()
     15    cursor.execute("DELETE FROM %s WHERE %s < NOW()" % \
     16        (backend.quote_name('django_session'), backend.quote_name('expire_date')))
    1817    transaction.commit_unless_managed()
    1918
    2019if __name__ == "__main__":
Back to Top