|
@@ -1,4 +1,7 @@
|
|
from sql import db
|
|
from sql import db
|
|
|
|
+from sql.cache import (read_comment_from_cache, write_comment_to_cache, delete_comment_from_cache,
|
|
|
|
+ get_user_comment_count_from_cache, write_user_comment_count_to_cache,
|
|
|
|
+ delete_all_user_comment_count_from_cache, delete_user_comment_count_from_cache)
|
|
|
|
|
|
|
|
|
|
def read_comment_list(blog_id: int):
|
|
def read_comment_list(blog_id: int):
|
|
@@ -14,6 +17,8 @@ def read_comment_list(blog_id: int):
|
|
|
|
|
|
def create_comment(blog_id: int, user_id: int, content: str):
|
|
def create_comment(blog_id: int, user_id: int, content: str):
|
|
""" 新建 comment """
|
|
""" 新建 comment """
|
|
|
|
+ delete_user_comment_count_from_cache(user_id)
|
|
|
|
+
|
|
content = content.replace("'", "''")
|
|
content = content.replace("'", "''")
|
|
cur = db.insert("INSERT INTO comment(BlogID, Auth, Content) "
|
|
cur = db.insert("INSERT INTO comment(BlogID, Auth, Content) "
|
|
"VALUES (%s, %s, %s)", blog_id, user_id, content)
|
|
"VALUES (%s, %s, %s)", blog_id, user_id, content)
|
|
@@ -24,14 +29,23 @@ def create_comment(blog_id: int, user_id: int, content: str):
|
|
|
|
|
|
def read_comment(comment_id: int):
|
|
def read_comment(comment_id: int):
|
|
""" 读取 comment """
|
|
""" 读取 comment """
|
|
|
|
+ res = read_comment_from_cache(comment_id)
|
|
|
|
+ if res is not None:
|
|
|
|
+ return res
|
|
|
|
+
|
|
cur = db.search("SELECT BlogID, Email, Content, UpdateTime FROM comment_user WHERE CommentID=%s", comment_id)
|
|
cur = db.search("SELECT BlogID, Email, Content, UpdateTime FROM comment_user WHERE CommentID=%s", comment_id)
|
|
if cur is None or cur.rowcount == 0:
|
|
if cur is None or cur.rowcount == 0:
|
|
return [-1, "", "", 0]
|
|
return [-1, "", "", 0]
|
|
- return cur.fetchone()
|
|
|
|
|
|
+
|
|
|
|
+ res = cur.fetchone()
|
|
|
|
+ write_comment_to_cache(comment_id, *res)
|
|
|
|
+ return res
|
|
|
|
|
|
|
|
|
|
def delete_comment(comment_id):
|
|
def delete_comment(comment_id):
|
|
""" 删除评论 """
|
|
""" 删除评论 """
|
|
|
|
+ delete_comment_from_cache(comment_id)
|
|
|
|
+ delete_all_user_comment_count_from_cache()
|
|
cur = db.delete("DELETE FROM comment WHERE ID=%s", comment_id)
|
|
cur = db.delete("DELETE FROM comment WHERE ID=%s", comment_id)
|
|
if cur is None or cur.rowcount == 0:
|
|
if cur is None or cur.rowcount == 0:
|
|
return False
|
|
return False
|