one query

This commit is contained in:
Chris Clark 2024-02-01 14:24:48 -05:00
parent d1c409b1ac
commit 6f0bb23102
2 changed files with 5 additions and 8 deletions

View file

@ -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

View file

@ -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