From 1899c1996e98452f9ab333d278e407a2d4ed43a7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tobias=20Kr=C3=B6nke?= Date: Mon, 3 Jun 2024 09:16:46 +0200 Subject: [PATCH] Replace expensive `count()` with cheap `exists()` (#478) --- model_bakery/recipe.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/model_bakery/recipe.py b/model_bakery/recipe.py index b302f96c..c1df72b8 100644 --- a/model_bakery/recipe.py +++ b/model_bakery/recipe.py @@ -52,7 +52,7 @@ def _mapping( # noqa: C901 m = finder.get_model(self._model) else: m = self._model - if k not in self._iterator_backups or m.objects.count() == 0: + if k not in self._iterator_backups or not m.objects.exists(): self._iterator_backups[k] = itertools.tee( self._iterator_backups.get(k, [v])[0] )