From: Marcin Koziej Date: Fri, 14 Sep 2012 10:57:33 +0000 (+0200) Subject: so apparent memory leak seems to be just connection.queries debugging of django. X-Git-Url: https://git.mdrn.pl/wolnelektury.git/commitdiff_plain/24c640c026288efce35548efa64a7f9918359d8f?ds=sidebyside;hp=--cc so apparent memory leak seems to be just connection.queries debugging of django. --- 24c640c026288efce35548efa64a7f9918359d8f diff --git a/apps/catalogue/management/commands/importbooks.py b/apps/catalogue/management/commands/importbooks.py index c1a743077..42554b78a 100644 --- a/apps/catalogue/management/commands/importbooks.py +++ b/apps/catalogue/management/commands/importbooks.py @@ -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) diff --git a/apps/catalogue/utils.py b/apps/catalogue/utils.py index 1ac0ee8d8..106067092 100644 --- a/apps/catalogue/utils.py +++ b/apps/catalogue/utils.py @@ -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 [] +