|
@@ -303,26 +303,20 @@ class EquipmentInfo(View):
|
|
|
use information_schema;
|
|
|
select concat(round(sum(data_length/1024/1024),2),'MB') as data from tables where table_schema='Ansjer81';
|
|
|
'''
|
|
|
-# 按季度删除访问日志
|
|
|
-def deleteExpireEquipmentInfo(request):
|
|
|
+# 删除访问日志
|
|
|
+def deleteExpireEquipmentInfo():
|
|
|
response = ResponseObject()
|
|
|
- i = int(request.GET.get('i', 5))
|
|
|
-
|
|
|
- import time
|
|
|
nowTime = int(time.time())
|
|
|
- # equipment_info_count = Equipment_Info.objects.filter(addTime__lte=str(nowTime - 3600 * 24 * 7)).count()
|
|
|
- # cycles_count = equipment_info_count % 10000
|
|
|
- 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))
|
|
|
- # print(id_list)
|
|
|
- Equipment_Info.objects.filter(id__in=id_list).delete()
|
|
|
- # id_list.clear()
|
|
|
- # time.sleep(2)
|
|
|
- return response.json(0)
|
|
|
- except Exception as e:
|
|
|
- return response.json(500, repr(e))
|
|
|
+ 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))
|
|
|
|
|
|
|