Bläddra i källkod

优化定时清除推送信息表功能

lhq 4 år sedan
förälder
incheckning
030115e6b6
1 ändrade filer med 8 tillägg och 11 borttagningar
  1. 8 11
      Controller/EquipmentInfo.py

+ 8 - 11
Controller/EquipmentInfo.py

@@ -308,16 +308,13 @@ def deleteExpireEquipmentInfo(request):
     response = ResponseObject()
     import time
     nowTime = int(time.time())
-    equipment_info_count = Equipment_Info.objects.filter(addTime__lte=str(nowTime - 3600 * 24 * 7)).count() # 删除7天前的数据
-    if equipment_info_count > 100000:   # 数据量大于10w才删
-        cycles_count = 10
-        try:
-            for i in range(cycles_count):
-                ei = Equipment_Info.objects.filter(addTime__lte=str(nowTime - 3600 * 24 * 7))[0:10000]
-                id_list = list(ei.values_list("id", flat=True))
-                Equipment_Info.objects.filter(id__in=id_list).delete()
-            return response.json(0)
-        except Exception as e:
-            return response.json(500, repr(e))
+    try:
+        for i in range(5):
+            ei = Equipment_Info.objects.filter(addTime__lte=str(nowTime - 3600 * 24 * 7))[0:10000]
+            id_list = list(ei.values_list("id", flat=True))
+            Equipment_Info.objects.filter(id__in=id_list).delete()
+        return response.json(0)
+    except Exception as e:
+        return response.json(500, repr(e))