Browse Source

update 股票更新后更新缓存

xjconline 4 months ago
parent
commit
c93793d07d
1 changed files with 6 additions and 2 deletions
  1. 6 2
      src/manage/controls.py

+ 6 - 2
src/manage/controls.py

@@ -278,6 +278,7 @@ def update_model(cls,**kwargs):
         today_stock = obj.today_stock
         today_stock = obj.today_stock
         new_stock_list = []
         new_stock_list = []
         today_stock_list = json.loads(today_stock)
         today_stock_list = json.loads(today_stock)
+        month = "%s%s" % (stock_date.split("-")[0],stock_date.split("-")[1])
         for ts in today_stock_list:
         for ts in today_stock_list:
             if ts["name"]:
             if ts["name"]:
                 try:
                 try:
@@ -285,7 +286,7 @@ def update_model(cls,**kwargs):
                         name = ts["name"] 
                         name = ts["name"] 
                     )
                     )
                     stock_id = stock.id
                     stock_id = stock.id
-                    usobj,flag = cm.UserStock.objects.get_or_create(
+                    usobj,flag = cm.UserStock.get_db_model(month).objects.get_or_create(
                         user_id = user_id, 
                         user_id = user_id, 
                         stock_id = stock_id,
                         stock_id = stock_id,
                         stock_name = ts["name"],
                         stock_name = ts["name"],
@@ -315,6 +316,9 @@ def update_model(cls,**kwargs):
     if model_name == "UserInfo":
     if model_name == "UserInfo":
         ccc.del_cache("cdata_get_user_info_(%s,)"%id)
         ccc.del_cache("cdata_get_user_info_(%s,)"%id)
 
 
+    if model_name == "Stock":
+        ccc.del_cache("cdata_get_stock_cache_(%sL,)"%id)
+
     return rst
     return rst
 
 
 
 
@@ -1420,7 +1424,7 @@ def update_stock_usernum(**kwargs):
     """
     """
     stock_date = kwargs.get("stock_date")
     stock_date = kwargs.get("stock_date")
     month = "%s%s" % (stock_date.split("-")[0],stock_date.split("-")[1])
     month = "%s%s" % (stock_date.split("-")[0],stock_date.split("-")[1])
-    qset = cm.UserStock.objects.filter(stock_date=stock_date,fund__gt=0)
+    qset = cm.UserStock.get_db_model(month).objects.filter(stock_date=stock_date,fund__gt=0)
     qset = qset.values("stock_id","stock_name").annotate(count=Count("stock_id"),total_fund=Sum("fund")).order_by("-count")
     qset = qset.values("stock_id","stock_name").annotate(count=Count("stock_id"),total_fund=Sum("fund")).order_by("-count")
     cm.Stock.objects.update(stock_date=None)
     cm.Stock.objects.update(stock_date=None)
     for q in qset:
     for q in qset: