diff --git a/beat/web/accounts/management/commands/clean_expired_temporary_urls.py b/beat/web/accounts/management/commands/clean_expired_temporary_urls.py
index 5537aea5453973c4901c8f07e0580ca021104777..97049e3b25af049f875566731ae32027a7987974 100644
--- a/beat/web/accounts/management/commands/clean_expired_temporary_urls.py
+++ b/beat/web/accounts/management/commands/clean_expired_temporary_urls.py
@@ -57,15 +57,10 @@ class Command(BaseCommand):
                 self.stdout.write('Clean expired temporary urls operation canceled')
                 sys.exit(1)
 
-        temporary_urls = TemporaryUrl.objects.all()
-        count = 0
-        for temporary_url in temporary_urls:
-            now = datetime.datetime.now()
-            if temporary_url.expires < now:
-                count+=1
-                temporary_url.delete()
-
-        self.stdout.write('{} Expired temporary url(s) successfully cleaned/'.format(count) + '{} Total temporary url(s) checked'.format(temporary_urls.count()))
+        temporary_urls_count = TemporaryUrl.objects.all().count()
+        now = datetime.datetime.now()
+        count = TemporaryUrl.objects.filter(expires__lt=now).delete()[0]
+        self.stdout.write('{} Expired temporary url(s) successfully cleaned/'.format(count) + '{} Total temporary url(s) checked'.format(temporary_urls_count))
 
 
     def get_input_data(self, message, default=None):