fix 部分api请求失败情况下,不会噶了
This commit is contained in:
parent
5d18f4193c
commit
a4ba8fa50d
@ -203,7 +203,7 @@ def msg_count():
|
||||
db_config = get_conf(g.caf, my_wxid, "db_config")
|
||||
db = DBHandler(db_config)
|
||||
chat_count = db.get_msg_count(wxid)
|
||||
chat_count1 = db.get_plc_msg_count(wxid)
|
||||
chat_count1 = db.get_plc_msg_count(wxid) if db.PublicMsg_exist else {}
|
||||
# 合并两个字典,相同key,则将value相加
|
||||
count = {k: chat_count.get(k, 0) + chat_count1.get(k, 0) for k in
|
||||
list(set(list(chat_count.keys()) + list(chat_count1.keys())))}
|
||||
@ -234,7 +234,7 @@ def get_msgs():
|
||||
|
||||
db = DBHandler(db_config)
|
||||
msgs, wxid_list = db.get_msg_list(wxid=wxid, start_index=start, page_size=limit)
|
||||
if not msgs:
|
||||
if not msgs and db.PublicMsg_exist:
|
||||
msgs, wxid_list = db.get_plc_msg_list(wxid=wxid, start_index=start, page_size=limit)
|
||||
wxid_list.append(my_wxid)
|
||||
user = db.get_user_list(wxids=wxid_list)
|
||||
|
@ -42,9 +42,6 @@ class DBHandler(MicroHandler, MediaHandler, OpenIMContactHandler, PublicMsgHandl
|
||||
if self.Micro_exist: # 添加索引
|
||||
self.Micro_add_index()
|
||||
|
||||
# print(self.MSG_exist, self.Micro_exist, self.Media_exist, self.OpenIMContact_exist, self.PublicMsg_exist,
|
||||
# self.OpenIMMedia_exist, self.Favorite_exist)
|
||||
|
||||
def get_user(self, word=None, wxids=None, labels=None):
|
||||
"""
|
||||
获取联系人列表
|
||||
|
@ -59,6 +59,8 @@ class MicroHandler(DatabaseBase):
|
||||
:param id_is_key: id_is_key: True: id作为key,False: name作为key
|
||||
:return:
|
||||
"""
|
||||
if (self.table_exist.get("ContactLabel") is None) or (not self.table_exist.get("ContactLabel")):
|
||||
return []
|
||||
sql = "SELECT LabelId, LabelName FROM ContactLabel ORDER BY LabelName ASC;"
|
||||
result = self.execute(sql)
|
||||
if not result:
|
||||
|
@ -79,6 +79,7 @@ class DatabaseSingletonBase:
|
||||
|
||||
class DatabaseBase(DatabaseSingletonBase):
|
||||
_class_name = "DatabaseBase"
|
||||
table_exist = {}
|
||||
|
||||
def __init__(self, db_config):
|
||||
"""
|
||||
@ -134,6 +135,7 @@ class DatabaseBase(DatabaseSingletonBase):
|
||||
f"WHERE type='table' AND tbl_name in ({required_tables_str});")
|
||||
existing_tables = self.execute(sql)
|
||||
existing_tables = [row[0] for row in existing_tables] # 将查询结果转换为列表
|
||||
self.table_exist = {table: table in existing_tables for table in required_tables}
|
||||
# 检查所有必需的表是否都在现有表中
|
||||
return all(table in existing_tables for table in required_tables)
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user