Commits

Anonymous committed ea1f4aa

Performance fixes to reduce number of DB queries

Comments (0)

Files changed (1)

         if not self.has_model():
             raise NotImplementedError
 
-        try:
-            self.model.objects.get(**kwargs)
+        if bool(self.model.objects.filter(**kwargs)):
             return True
-        except ObjectDoesNotExist:
+        else:
             return False
 
     def read(self, request, *args, **kwargs):
     def delete(self, request, *args, **kwargs):
         if not self.has_model():
             raise NotImplementedError
-
-        try:
-            inst = self.queryset(request).get(**kwargs)
-            inst.delete()
+        
+        queryset = self.queryset(request).filter(**kwargs)
+        count = queryset.count()
+        if count == 1: 
+            queryset.delete()
             return rc.DELETED
-        except MultipleObjectsReturned:
+        elif count > 1:
             return rc.DUPLICATE_ENTRY
-        except ObjectDoesNotExist:
+        else:
             return rc.NOT_HERE
 
 class AnonymousBaseHandler(BaseHandler):