mirror of
				https://github.com/TitanEmbeds/Titan.git
				synced 2025-11-04 15:57:02 +01:00 
			
		
		
		
	Attempt to fix cleanup 2
code looks much cleaner too
This commit is contained in:
		
				
					committed by
					
						
						GitHub
					
				
			
			
				
	
			
			
			
						parent
						
							efcd2d9a83
						
					
				
				
					commit
					44af174287
				
			@@ -467,22 +467,19 @@ def create_authenticated_user():
 | 
				
			|||||||
@api.route("/cleanup-db", methods=["DELETE"])
 | 
					@api.route("/cleanup-db", methods=["DELETE"])
 | 
				
			||||||
def cleanup_keyval_db():
 | 
					def cleanup_keyval_db():
 | 
				
			||||||
    if request.form.get("secret", None) == config["app-secret"]:
 | 
					    if request.form.get("secret", None) == config["app-secret"]:
 | 
				
			||||||
        q = KeyValueProperties.query.filter(KeyValueProperties.expiration < datetime.datetime.now()).all()
 | 
					        db.session.query(KeyValueProperties).filter(KeyValueProperties.expiration < datetime.datetime.now()).delete()
 | 
				
			||||||
        for m in q:
 | 
					 | 
				
			||||||
            db.session.delete(m)
 | 
					 | 
				
			||||||
        db.session.commit()
 | 
					        db.session.commit()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        guilds = Guilds.query.all()
 | 
					        guilds = Guilds.query.all()
 | 
				
			||||||
        for guild in guilds:
 | 
					        for guild in guilds:
 | 
				
			||||||
 | 
					            try:
 | 
				
			||||||
                channelsjson = json.loads(guild.channels)
 | 
					                channelsjson = json.loads(guild.channels)
 | 
				
			||||||
 | 
					            except:
 | 
				
			||||||
 | 
					                continue
 | 
				
			||||||
            for channel in channelsjson:
 | 
					            for channel in channelsjson:
 | 
				
			||||||
                chanid = channel["id"]
 | 
					                chanid = channel["id"]
 | 
				
			||||||
                dbmsg = Messages.query.filter(Messages.channel_id == chanid).all()
 | 
					                db.session.query(Messages).filter(Messages.channel_id == chanid).order_by(Messages.timestamp.desc()).offset(50).delete()
 | 
				
			||||||
                for idx, val in enumerate(dbmsg):
 | 
					 | 
				
			||||||
                    if len(dbmsg) - idx > 50:
 | 
					 | 
				
			||||||
                        db.session.delete(val)
 | 
					 | 
				
			||||||
            db.session.commit()
 | 
					            db.session.commit()
 | 
				
			||||||
                    else:
 | 
					                
 | 
				
			||||||
                        continue
 | 
					 | 
				
			||||||
        return ('', 204)
 | 
					        return ('', 204)
 | 
				
			||||||
    abort(401)
 | 
					    abort(401)
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user