mirror of
https://github.com/TitanEmbeds/Titan.git
synced 2024-12-23 21:47:04 +01:00
Resolve messages duplicates in database and order messages by timestamp
This commit is contained in:
parent
38df1a8ed0
commit
5505928e5b
@ -31,11 +31,15 @@ class Messages(db.Model):
|
||||
|
||||
def get_channel_messages(channel_id, after_snowflake=None):
|
||||
if not after_snowflake:
|
||||
q = db.session.query(Messages).filter(Messages.channel_id == channel_id).order_by(Messages.id.desc()).limit(50)
|
||||
q = db.session.query(Messages).filter(Messages.channel_id == channel_id).order_by(Messages.timestamp.desc()).limit(50)
|
||||
else:
|
||||
q = db.session.query(Messages).filter(cast(Messages.channel_id, db.Integer) == int(channel_id)).filter(Messages.message_id > after_snowflake).order_by(Messages.id.desc()).limit(50)
|
||||
q = db.session.query(Messages).filter(cast(Messages.channel_id, db.Integer) == int(channel_id)).filter(Messages.message_id > after_snowflake).order_by(Messages.timestamp.desc()).limit(50)
|
||||
msgs = []
|
||||
snowflakes = []
|
||||
for x in q:
|
||||
if x.message_id in snowflakes:
|
||||
continue
|
||||
snowflakes.append(x.message_id)
|
||||
msgs.append({
|
||||
"attachments": json.loads(x.attachments),
|
||||
"timestamp": x.timestamp,
|
||||
|
Loading…
Reference in New Issue
Block a user