so apparent memory leak seems to be just connection.queries debugging of django.
authorMarcin Koziej <marcin.koziej@nowoczesnapolska.org.pl>
Fri, 14 Sep 2012 10:57:33 +0000 (12:57 +0200)
committerMarcin Koziej <marcin.koziej@nowoczesnapolska.org.pl>
Fri, 14 Sep 2012 10:57:33 +0000 (12:57 +0200)
apps/catalogue/management/commands/importbooks.py
apps/catalogue/utils.py

index c1a7430..42554b7 100644 (file)
@@ -10,6 +10,7 @@ from django.conf import settings
 from django.core.management.base import BaseCommand
 from django.core.management.color import color_style
 from django.core.files import File
+from catalogue.utils import trim_query_log
 
 from wolnelektury_core.management.profile import profile
 import objgraph
@@ -109,6 +110,7 @@ class Command(BaseCommand):
                 files = sorted(os.listdir(dir_name))
                 postponed = {}
                 while files:
+                    trim_query_log(0)
                     file_name = files.pop(0)
                     file_path = os.path.join(dir_name, file_name)
                     file_base, ext = os.path.splitext(file_path)
index 1ac0ee8..1060670 100644 (file)
@@ -300,3 +300,16 @@ class AppSettings(object):
         if hasattr(self, more):
             value = getattr(self, more)(value)
         return value
+
+
+def trim_query_log(trim_to=25):
+    """
+connection.queries includes all SQL statements -- INSERTs, UPDATES, SELECTs, etc. Each time your app hits the database, the query will be recorded.
+This can sometimes occupy lots of memory, so trim it here a bit.
+    """
+    if settings.DEBUG:
+        from django.db import connection
+        connection.queries = trim_to > 0 \
+            and connection.queries[-trim_to:] \
+            or []
+