以MsgSvrID作为判断消息唯一性的key,彻底解决消息重复出现问题

This commit is contained in:
STDquantum 2023-12-13 14:41:07 +08:00
parent 15cffce3ff
commit 3d68f99780

View File

@ -63,6 +63,7 @@ class Msg:
select localId,TalkerId,Type,SubType,IsSender,CreateTime,Status,StrContent,strftime('%Y-%m-%d %H:%M:%S',CreateTime,'unixepoch','localtime') as StrTime,MsgSvrID,BytesExtra,CompressContent select localId,TalkerId,Type,SubType,IsSender,CreateTime,Status,StrContent,strftime('%Y-%m-%d %H:%M:%S',CreateTime,'unixepoch','localtime') as StrTime,MsgSvrID,BytesExtra,CompressContent
from MSG from MSG
where StrTalker=? where StrTalker=?
group by MsgSvrID
order by CreateTime order by CreateTime
''' '''
try: try:
@ -78,6 +79,7 @@ class Msg:
sql = ''' sql = '''
select localId,TalkerId,Type,SubType,IsSender,CreateTime,Status,StrContent,strftime('%Y-%m-%d %H:%M:%S',CreateTime,'unixepoch','localtime') as StrTime,MsgSvrID,BytesExtra,StrTalker,Reserved1,CompressContent select localId,TalkerId,Type,SubType,IsSender,CreateTime,Status,StrContent,strftime('%Y-%m-%d %H:%M:%S',CreateTime,'unixepoch','localtime') as StrTime,MsgSvrID,BytesExtra,StrTalker,Reserved1,CompressContent
from MSG from MSG
group by MsgSvrID
order by CreateTime order by CreateTime
''' '''
if not self.open_flag: if not self.open_flag:
@ -94,6 +96,7 @@ class Msg:
def get_messages_length(self): def get_messages_length(self):
sql = ''' sql = '''
select count(*) select count(*)
group by MsgSvrID
from MSG from MSG
''' '''
if not self.open_flag: if not self.open_flag:
@ -113,6 +116,7 @@ class Msg:
select localId,TalkerId,Type,SubType,IsSender,CreateTime,Status,StrContent,strftime('%Y-%m-%d %H:%M:%S',CreateTime,'unixepoch','localtime') as StrTime,MsgSvrID,BytesExtra,CompressContent select localId,TalkerId,Type,SubType,IsSender,CreateTime,Status,StrContent,strftime('%Y-%m-%d %H:%M:%S',CreateTime,'unixepoch','localtime') as StrTime,MsgSvrID,BytesExtra,CompressContent
from MSG from MSG
where StrTalker = ? and localId < ? where StrTalker = ? and localId < ?
group by MsgSvrID
order by CreateTime desc order by CreateTime desc
limit 20 limit 20
''' '''
@ -138,6 +142,7 @@ class Msg:
select localId,TalkerId,Type,SubType,IsSender,CreateTime,Status,StrContent,strftime('%Y-%m-%d %H:%M:%S',CreateTime,'unixepoch','localtime') as StrTime,MsgSvrID,BytesExtra,CompressContent select localId,TalkerId,Type,SubType,IsSender,CreateTime,Status,StrContent,strftime('%Y-%m-%d %H:%M:%S',CreateTime,'unixepoch','localtime') as StrTime,MsgSvrID,BytesExtra,CompressContent
from MSG from MSG
where StrTalker=? and Type=? and strftime('%Y',CreateTime,'unixepoch','localtime') = ? where StrTalker=? and Type=? and strftime('%Y',CreateTime,'unixepoch','localtime') = ?
group by MsgSvrID
order by CreateTime order by CreateTime
''' '''
else: else:
@ -145,6 +150,7 @@ class Msg:
select localId,TalkerId,Type,SubType,IsSender,CreateTime,Status,StrContent,strftime('%Y-%m-%d %H:%M:%S',CreateTime,'unixepoch','localtime') as StrTime,MsgSvrID,BytesExtra,CompressContent select localId,TalkerId,Type,SubType,IsSender,CreateTime,Status,StrContent,strftime('%Y-%m-%d %H:%M:%S',CreateTime,'unixepoch','localtime') as StrTime,MsgSvrID,BytesExtra,CompressContent
from MSG from MSG
where StrTalker=? and Type=? where StrTalker=? and Type=?
group by MsgSvrID
order by CreateTime order by CreateTime
''' '''
try: try:
@ -165,6 +171,7 @@ class Msg:
select localId,TalkerId,Type,SubType,IsSender,CreateTime,Status,StrContent,strftime('%Y-%m-%d %H:%M:%S',CreateTime,'unixepoch','localtime') as StrTime,MsgSvrID,BytesExtra select localId,TalkerId,Type,SubType,IsSender,CreateTime,Status,StrContent,strftime('%Y-%m-%d %H:%M:%S',CreateTime,'unixepoch','localtime') as StrTime,MsgSvrID,BytesExtra
from MSG from MSG
where StrTalker=? and Type=1 and LENGTH(StrContent)<? and StrContent like ? where StrTalker=? and Type=1 and LENGTH(StrContent)<? and StrContent like ?
group by MsgSvrID
order by CreateTime desc order by CreateTime desc
''' '''
temp = [] temp = []
@ -185,6 +192,7 @@ class Msg:
select localId,TalkerId,Type,SubType,IsSender,CreateTime,Status,StrContent,strftime('%Y-%m-%d %H:%M:%S',CreateTime,'unixepoch','localtime') as StrTime,MsgSvrID select localId,TalkerId,Type,SubType,IsSender,CreateTime,Status,StrContent,strftime('%Y-%m-%d %H:%M:%S',CreateTime,'unixepoch','localtime') as StrTime,MsgSvrID
from MSG from MSG
where localId > ? and StrTalker=? and Type=1 and IsSender=? where localId > ? and StrTalker=? and Type=1 and IsSender=?
group by MsgSvrID
limit 1 limit 1
''' '''
self.cursor.execute(sql, [local_id, username_, 1 - is_send]) self.cursor.execute(sql, [local_id, username_, 1 - is_send])
@ -205,15 +213,23 @@ class Msg:
if is_Annual_report_: if is_Annual_report_:
sql = ''' sql = '''
SELECT strftime('%Y-%m-%d',CreateTime,'unixepoch','localtime') as days,count(MsgSvrID) SELECT strftime('%Y-%m-%d',CreateTime,'unixepoch','localtime') as days,count(MsgSvrID)
from MSG from (
where StrTalker = ? and strftime('%Y',CreateTime,'unixepoch','localtime') = ? SELECT MsgSvrID, CreateTime
FROM MSG
WHERE StrTalker = ? AND strftime('%Y', CreateTime, 'unixepoch', 'localtime') = ?
GROUP BY MsgSvrID
)
group by days group by days
''' '''
else: else:
sql = ''' sql = '''
SELECT strftime('%Y-%m-%d',CreateTime,'unixepoch','localtime') as days,count(MsgSvrID) SELECT strftime('%Y-%m-%d',CreateTime,'unixepoch','localtime') as days,count(MsgSvrID)
from MSG from (
where StrTalker = ? SELECT MsgSvrID, CreateTime
FROM MSG
WHERE StrTalker = ?
GROUP BY MsgSvrID
)
group by days group by days
''' '''
result = None result = None
@ -233,16 +249,24 @@ class Msg:
def get_messages_by_month(self, username_, is_Annual_report_=False, year_='2023'): def get_messages_by_month(self, username_, is_Annual_report_=False, year_='2023'):
if is_Annual_report_: if is_Annual_report_:
sql = ''' sql = '''
SELECT strftime('%Y-%m',CreateTime,'unixepoch','localtime') as days,count(MsgSvrID) SELECT strftime('%Y-%m',CreateTime,'unixepoch','localtime') as days,count(MsgSvrID)
from MSG from (
where StrTalker = ? and strftime('%Y',CreateTime,'unixepoch','localtime') = ? SELECT MsgSvrID, CreateTime
group by days FROM MSG
WHERE StrTalker = ? AND strftime('%Y', CreateTime, 'unixepoch', 'localtime') = ?
GROUP BY MsgSvrID
)
group by days
''' '''
else: else:
sql = ''' sql = '''
SELECT strftime('%Y-%m',CreateTime,'unixepoch','localtime') as days,count(MsgSvrID) SELECT strftime('%Y-%m',CreateTime,'unixepoch','localtime') as days,count(MsgSvrID)
from MSG from (
where StrTalker = ? SELECT MsgSvrID, CreateTime
FROM MSG
WHERE StrTalker = ?
GROUP BY MsgSvrID
)
group by days group by days
''' '''
result = None result = None
@ -265,16 +289,24 @@ class Msg:
def get_messages_by_hour(self, username_, is_Annual_report_=False, year_='2023'): def get_messages_by_hour(self, username_, is_Annual_report_=False, year_='2023'):
if is_Annual_report_: if is_Annual_report_:
sql = ''' sql = '''
SELECT strftime('%H:00',CreateTime,'unixepoch','localtime') as hours,count(MsgSvrID) SELECT strftime('%H:00',CreateTime,'unixepoch','localtime') as hours,count(MsgSvrID)
from MSG from (
SELECT MsgSvrID, CreateTime
FROM MSG
where StrTalker = ? and strftime('%Y',CreateTime,'unixepoch','localtime') = ? where StrTalker = ? and strftime('%Y',CreateTime,'unixepoch','localtime') = ?
group by hours GROUP BY MsgSvrID
)
group by hours
''' '''
else: else:
sql = ''' sql = '''
SELECT strftime('%H:00',CreateTime,'unixepoch','localtime') as hours,count(MsgSvrID) SELECT strftime('%H:00',CreateTime,'unixepoch','localtime') as hours,count(MsgSvrID)
from MSG from (
where StrTalker = ? SELECT MsgSvrID, CreateTime
FROM MSG
where StrTalker = ?
GROUP BY MsgSvrID
)
group by hours group by hours
''' '''
result = None result = None