Browse Source

feat: 刷新缓存

SongZihuan 2 years ago
parent
commit
a92ec2b1c1
5 changed files with 8 additions and 2 deletions
  1. 1 0
      sql/archive.py
  2. 4 2
      sql/blog.py
  3. 1 0
      sql/comment.py
  4. 1 0
      sql/msg.py
  5. 1 0
      sql/user.py

+ 1 - 0
sql/archive.py

@@ -11,6 +11,7 @@ def create_archive(name: str, describe: str):
                     "VALUES (%s, %s)", name, describe)
     if cur is None or cur.rowcount == 0:
         return None
+    read_archive(cur.lastrowid)
     return cur.lastrowid
 
 

+ 4 - 2
sql/blog.py

@@ -28,10 +28,10 @@ def create_blog(auth_id: int, title: str, subtitle: str, content: str,
 
     blog_id = cur.lastrowid
     for archive in archive_list:
-        delete_archive_blog_count_from_cache(archive.id)
         if not add_blog_to_archive(blog_id, archive.id):
             return False
-
+        delete_archive_blog_count_from_cache(archive.id)
+    read_blog(blog_id)  # 刷新缓存
     return True
 
 
@@ -44,6 +44,7 @@ def update_blog(blog_id: int, content: str) -> bool:
                     "WHERE ID=%s", content, blog_id)
     if cur is None or cur.rowcount != 1:
         return False
+    read_blog(blog_id)  # 刷新缓存
     return True
 
 
@@ -89,6 +90,7 @@ def set_blog_top(blog_id: int, top: bool = True):
                     "WHERE ID=%s", 1 if top else 0, blog_id)
     if cur is None or cur.rowcount != 1:
         return False
+    read_blog(blog_id)  # 刷新缓存
     return True
 
 

+ 1 - 0
sql/comment.py

@@ -23,6 +23,7 @@ def create_comment(blog_id: int, user_id: int, content: str):
                     "VALUES (%s, %s, %s)", blog_id, user_id, content)
     if cur is None or cur.rowcount == 0:
         return False
+    read_comment(cur.lastrowid)  # 刷新缓存
     return True
 
 

+ 1 - 0
sql/msg.py

@@ -47,6 +47,7 @@ def create_msg(auth: int, content: str, secret: bool = False):
                     "VALUES (%s, %s, %s)", auth, content, 1 if secret else 0)
     if cur is None or cur.rowcount != 1:
         return None
+    read_msg(cur.lastrowid)  # 刷新缓存
     return cur.lastrowid
 
 

+ 1 - 0
sql/user.py

@@ -45,6 +45,7 @@ def create_user(email: str, passwd: str):
                         "VALUES (%s, %s)", email, passwd)
     if cur is None or cur.rowcount != 1:
         return None
+    read_user(cur.lastrowid)  # 刷新缓存
     return cur.lastrowid