mirror of
https://github.com/TitanEmbeds/Titan.git
synced 2024-11-14 18:11:23 +01:00
Better cleanup db msgs?
This commit is contained in:
parent
956e466db1
commit
c0798bd5b1
@ -80,10 +80,9 @@ class Titan(discord.Client):
|
|||||||
continue
|
continue
|
||||||
for channel in channelsjson:
|
for channel in channelsjson:
|
||||||
chanid = channel["id"]
|
chanid = channel["id"]
|
||||||
msgs = session.query(Messages).filter(Messages.channel_id == chanid).order_by(Messages.timestamp.desc()).offset(50).all()
|
keep_these = session.query(Messages.id).filter(Messages.channel_id == chanid).order_by(Messages.timestamp.desc()).limit(50)
|
||||||
for msg in msgs:
|
session.query(Messages).filter(Messages.channel_id == chanid, ~Messages.id.in_(keep_these)).delete(synchronize_session=False)
|
||||||
session.delete(msg)
|
session.commit()
|
||||||
session.commit()
|
|
||||||
print("done!")
|
print("done!")
|
||||||
await self.logout()
|
await self.logout()
|
||||||
|
|
||||||
|
@ -436,18 +436,16 @@ def cleanup_keyval_db():
|
|||||||
db.session.query(KeyValueProperties).filter(KeyValueProperties.expiration < datetime.datetime.now()).delete()
|
db.session.query(KeyValueProperties).filter(KeyValueProperties.expiration < datetime.datetime.now()).delete()
|
||||||
db.session.commit()
|
db.session.commit()
|
||||||
|
|
||||||
# guilds = Guilds.query.all()
|
guilds = Guilds.query.all()
|
||||||
# for guild in guilds:
|
for guild in guilds:
|
||||||
# try:
|
try:
|
||||||
# channelsjson = json.loads(guild.channels)
|
channelsjson = json.loads(guild.channels)
|
||||||
# except:
|
except:
|
||||||
# continue
|
continue
|
||||||
# for channel in channelsjson:
|
for channel in channelsjson:
|
||||||
# chanid = channel["id"]
|
chanid = channel["id"]
|
||||||
# msgs = db.session.query(Messages).filter(Messages.channel_id == chanid).order_by(Messages.timestamp.desc()).offset(50).all()
|
keep_these = db.session.query(Messages.id).filter(Messages.channel_id == chanid).order_by(Messages.timestamp.desc()).limit(50)
|
||||||
# for msg in msgs:
|
db.session.query(Messages).filter(Messages.channel_id == chanid, ~Messages.id.in_(keep_these)).delete(synchronize_session=False)
|
||||||
# db.session.delete(msg)
|
db.session.commit()
|
||||||
# db.session.commit()
|
|
||||||
|
|
||||||
return ('', 204)
|
return ('', 204)
|
||||||
abort(401)
|
abort(401)
|
||||||
|
Loading…
Reference in New Issue
Block a user