diff --git a/django/db/__init__.py b/django/db/__init__.py
index ea353e4..21bf58d 100644
a
|
b
|
from django.conf import settings
|
2 | 2 | from django.core import signals |
3 | 3 | from django.core.exceptions import ImproperlyConfigured |
4 | 4 | from django.db.utils import ConnectionHandler, load_backend |
| 5 | from django.utils.datastructures import RingBuffer |
5 | 6 | from django.utils.functional import curry |
6 | 7 | |
7 | 8 | __all__ = ('backend', 'connection', 'connections', 'DatabaseError', |
… |
… |
signals.request_finished.connect(close_connection)
|
87 | 88 | # when a Django request is started. |
88 | 89 | def reset_queries(**kwargs): |
89 | 90 | for conn in connections.all(): |
90 | | conn.queries = [] |
| 91 | conn.queries = RingBuffer(100) |
91 | 92 | signals.request_started.connect(reset_queries) |
92 | 93 | |
93 | 94 | # Register an event that rolls back the connections |
diff --git a/django/db/backends/__init__.py b/django/db/backends/__init__.py
index bf3e9db..7cb242a 100644
a
|
b
|
from threading import local
|
4 | 4 | from django.db import DEFAULT_DB_ALIAS |
5 | 5 | from django.db.backends import util |
6 | 6 | from django.utils import datetime_safe |
| 7 | from django.utils.datastructures import RingBuffer |
7 | 8 | from django.utils.importlib import import_module |
8 | 9 | |
9 | 10 | class BaseDatabaseWrapper(local): |
… |
… |
class BaseDatabaseWrapper(local):
|
17 | 18 | # NAME, USER, etc. It's called `settings_dict` instead of `settings` |
18 | 19 | # to disambiguate it from Django settings modules. |
19 | 20 | self.connection = None |
20 | | self.queries = [] |
| 21 | self.queries = RingBuffer(100) |
21 | 22 | self.settings_dict = settings_dict |
22 | 23 | self.alias = alias |
23 | 24 | |
diff --git a/django/utils/datastructures.py b/django/utils/datastructures.py
index d6fc9dc..5c37313 100644
a
|
b
|
|
| 1 | import collections |
1 | 2 | from types import GeneratorType |
2 | 3 | |
3 | 4 | from django.utils.copycompat import deepcopy |
… |
… |
class DictWrapper(dict):
|
447 | 448 | return self.func(value) |
448 | 449 | return value |
449 | 450 | |
| 451 | class RingBuffer(collections.deque): |
| 452 | def __init__(self, size): |
| 453 | collections.deque.__init__(self) |
| 454 | self.size = size |
| 455 | |
| 456 | def append(self, item): |
| 457 | collections.deque.append(self, item) |
| 458 | if len(self) > self.size: |
| 459 | self.popleft() |
| 460 | |
| 461 | def get(self): |
| 462 | return list(self) |
| 463 | |
diff --git a/tests/regressiontests/datastructures/tests.py b/tests/regressiontests/datastructures/tests.py
index b7885e6..7315d4b 100644
a
|
b
|
AttributeError: Object is immutable!
|
159 | 159 | >>> "Normal: %(a)s. Modified: %(xx_a)s" % d |
160 | 160 | 'Normal: a. Modified: *a' |
161 | 161 | |
| 162 | ### RingBuffer ############################################################## |
| 163 | |
| 164 | >>> r = RingBuffer(3) |
| 165 | >>> r.append(1) |
| 166 | >>> r.get() |
| 167 | [1] |
| 168 | >>> r.append(2) |
| 169 | >>> r.append(3) |
| 170 | >>> r.get() |
| 171 | [1, 2, 3] |
| 172 | >>> r.append(4) |
| 173 | >>> r.get() |
| 174 | [2, 3, 4] |
| 175 | |
162 | 176 | """ |