From 24c640c026288efce35548efa64a7f9918359d8f Mon Sep 17 00:00:00 2001 From: Marcin Koziej Date: Fri, 14 Sep 2012 12:57:33 +0200 Subject: [PATCH] so apparent memory leak seems to be just connection.queries debugging of django. --- apps/catalogue/management/commands/importbooks.py | 2 ++ apps/catalogue/utils.py | 13 +++++++++++++ 2 files changed, 15 insertions(+) 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 [] + -- 2.20.1