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):
|
||||
key = self.add_prefix(key)
|
||||
value = None
|
||||
if self._cache:
|
||||
value = self._cache.get(key)
|
||||
if value is None:
|
||||
self.autofill()
|
||||
value = self._cache.get(key)
|
||||
else:
|
||||
value = None
|
||||
if value is None:
|
||||
match = self._model._default_manager.filter(key=key)
|
||||
if len(match) == 0:
|
||||
pass
|
||||
else:
|
||||
value = match.first().value
|
||||
match = self._model._default_manager.filter(key=key).first()
|
||||
if match:
|
||||
value = match.value
|
||||
if self._cache:
|
||||
self._cache.add(key, value)
|
||||
return value
|
||||
|
|
|
|||
|
|
@ -16,7 +16,7 @@ class TestDatabase(StorageTestsMixin, TestCase):
|
|||
with self.assertNumQueries(5):
|
||||
self.config.INT_VALUE
|
||||
|
||||
# Read
|
||||
# Read again
|
||||
with self.assertNumQueries(1):
|
||||
self.config.INT_VALUE
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue