mirror of
https://github.com/jazzband/django-constance.git
synced 2026-03-16 22:40:24 +00:00
one query
This commit is contained in:
parent
d1c409b1ac
commit
6f0bb23102
2 changed files with 5 additions and 8 deletions
|
|
@ -68,19 +68,16 @@ class DatabaseBackend(Backend):
|
||||||
|
|
||||||
def get(self, key):
|
def get(self, key):
|
||||||
key = self.add_prefix(key)
|
key = self.add_prefix(key)
|
||||||
|
value = None
|
||||||
if self._cache:
|
if self._cache:
|
||||||
value = self._cache.get(key)
|
value = self._cache.get(key)
|
||||||
if value is None:
|
if value is None:
|
||||||
self.autofill()
|
self.autofill()
|
||||||
value = self._cache.get(key)
|
value = self._cache.get(key)
|
||||||
else:
|
|
||||||
value = None
|
|
||||||
if value is None:
|
if value is None:
|
||||||
match = self._model._default_manager.filter(key=key)
|
match = self._model._default_manager.filter(key=key).first()
|
||||||
if len(match) == 0:
|
if match:
|
||||||
pass
|
value = match.value
|
||||||
else:
|
|
||||||
value = match.first().value
|
|
||||||
if self._cache:
|
if self._cache:
|
||||||
self._cache.add(key, value)
|
self._cache.add(key, value)
|
||||||
return value
|
return value
|
||||||
|
|
|
||||||
|
|
@ -16,7 +16,7 @@ class TestDatabase(StorageTestsMixin, TestCase):
|
||||||
with self.assertNumQueries(5):
|
with self.assertNumQueries(5):
|
||||||
self.config.INT_VALUE
|
self.config.INT_VALUE
|
||||||
|
|
||||||
# Read
|
# Read again
|
||||||
with self.assertNumQueries(1):
|
with self.assertNumQueries(1):
|
||||||
self.config.INT_VALUE
|
self.config.INT_VALUE
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue