Browse Source

添加缓存机制

pengzhibo168 5 years ago
parent
commit
a5a2f88b5a
4 changed files with 24 additions and 1 deletions
  1. 3 0
      Controller/DeviceManage.py
  2. 14 1
      Controller/EquipmentManager.py
  3. 2 0
      Controller/UIDPreview.py
  4. 5 0
      Controller/UidUser.py

+ 3 - 0
Controller/DeviceManage.py

@@ -21,6 +21,7 @@ from Service.CommonService import CommonService
 from Model.models import Device_Info
 import traceback,datetime
 from django.utils import timezone
+from Object.RedisObject import RedisObject
 '''
 http://192.168.136.40:8077/device/manage?operation=query&token=test&page=1&line=10
 http://192.168.136.40:8077/device/manage?operation=delete&id=1&id=2
@@ -101,6 +102,8 @@ class DeviceManage(View):
 
     def delete(self, request_dict, userID, response):
         own_perm = ModelService.check_perm(userID=userID, permID=10)
+        redisObj = RedisObject(db=8)
+        redisObj.del_data(key='uid_qs_' + userID)
         if own_perm is True:
             id = request_dict.get('id', None)
             if id:

+ 14 - 1
Controller/EquipmentManager.py

@@ -15,7 +15,7 @@ from Ansjer.config import OSS_STS_ACCESS_SECRET, OSS_STS_ACCESS_KEY
 from Object.ETkObject import ETkObject
 import oss2
 from django.http import JsonResponse
-
+from Object.RedisObject import RedisObject
 
 #     查询用户设备
 def queryUserEquipmentInterface(request):
@@ -85,6 +85,8 @@ def addNewUserEquipmentInterface(request):
         if dValid:
             return response.json(174)
         else:
+            redisObj = RedisObject(db=8)
+            redisObj.del_data(key='uid_qs_' + userID)
             UID = deviceData.get('UID', '')
             re_uid = re.compile(r'^[A-Za-z0-9]{20}$')
             if re_uid.match(UID):
@@ -149,8 +151,12 @@ def delUserEquipmentInterface(request):
     # 主用户删除设备全部删除
     try:
         dv_qs = Device_Info.objects.filter(userID_id=userID, id=id)
+        redisObj = RedisObject(db=8)
+        redisObj.del_data(key='uid_qs_' + userID)
         if dv_qs.exists():
             uid = dv_qs[0].UID
+            print('删除')
+            UID_Preview.objects.filter(uid=uid).delete()
             dv_qs.delete()
             asy = threading.Thread(target=ModelService.del_eq_info, args=(userID, uid))
             asy.start()
@@ -368,6 +374,8 @@ def addInterface(request):
                                              NickName=NickName, View_Account=View_Account,
                                              View_Password=View_Password, Type=Type, ChannelIndex=ChannelIndex)
                     userDevice.save()
+                    redisObj = RedisObject(db=8)
+                    redisObj.del_data(key='uid_qs_' + userID)
                 except Exception as e:
                     return response.json(10, repr(e))
                 else:
@@ -481,6 +489,8 @@ def admin_addInterface(request):
         else:
             UID = deviceData.get('UID', '')
             re_uid = re.compile(r'^[A-Za-z0-9]{20}$')
+            redisObj = RedisObject(db=8)
+            redisObj.del_data(key='uid_qs_' + userID)
             if re_uid.match(UID):
                 userDevice = Device_Info(id=CommonService.getUserID(getUser=False), userID_id=userID,
                                          **deviceData)
@@ -535,6 +545,7 @@ def admin_modifyInterface(request):
         return response.json(444, 'username')
     id = request_dict.get('id', None)
     print(deviceContent)
+
     if not deviceContent or not id:
         return response.json(444, 'content,id')
     tko = TokenObject(token)
@@ -552,6 +563,8 @@ def admin_modifyInterface(request):
 
     deviceData = json.loads(deviceContent)
     print(deviceData['UID'])
+    redisObj = RedisObject(db=8)
+    redisObj.del_data(key='uid_qs_' + userID)
     dValid = Device_Info.objects.filter(userID_id=userID, UID=deviceData['UID'])
     if dValid.exists():
         dValid_dict = CommonService.qs_to_dict(dValid)

+ 2 - 0
Controller/UIDPreview.py

@@ -147,6 +147,8 @@ class UIDPreview(View):
         own_perm = ModelService.check_perm(userID, 20)
         if own_perm is True:
             id = request_dict.get('id')
+            redisObj = RedisObject(db=8)
+            redisObj.del_data(key='uid_qs_' + userID)
             UID_Preview.objects.filter(id=id).delete()
             return response.json(0)
         else:

+ 5 - 0
Controller/UidUser.py

@@ -27,6 +27,7 @@ from Object.ResponseObject import ResponseObject
 from Object.TokenObject import TokenObject
 from Service.CommonService import CommonService
 from Service.ModelService import ModelService
+from Object.RedisObject import RedisObject
 '''
 http://192.168.136.40:8077/uiduser/add?token=local&UID=z123asdfqwerzxcvqw12&NickName=xxoxox&View_Account=user&View_Password=password&ChannelIndex=8&is_ap=1&Type=5&NickName=1234zcxv
 http://192.168.136.40:8077/uiduser/query?token=local&page=1&line=10&is_ap=1&NickName=1234zcxv&uid=zxcvasdfqwerzxcvqwer
@@ -127,6 +128,8 @@ def queryInterface(request):
     response.lang = tko.lang
     if page <= 0:
         return response.json(0)
+    redisObj = RedisObject(db=8)
+    redisObj.del_data(key='uid_qs_' + userID)
     if tko.code == 0:
         userID = tko.userID
         uid_user_qs = UidUserModel.objects.filter(userID_id=userID)
@@ -252,6 +255,8 @@ def deleteInterface(request):
         response.lang = tko.lang
         if tko.code == 0:
             userID = tko.userID
+            redisObj = RedisObject(db=8)
+            redisObj.del_data(key='uid_qs_' + userID)
             uid_user_qs = UidUserModel.objects.filter(userID_id=userID, id=id)
             if uid_user_qs.exists():
                 uid_user_qs.delete()