Skip to content

Commit

Permalink
fix: Fix position ti place delete user
Browse files Browse the repository at this point in the history
  • Loading branch information
WCY-dt committed Dec 17, 2024
1 parent ee41f7c commit 5b971ee
Showing 1 changed file with 11 additions and 14 deletions.
25 changes: 11 additions & 14 deletions my-github-2024.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,17 @@ class UserContext(db.Model):
with app.app_context():
db.create_all()

missing_users = (
db.session.query(RequestedUser)
.outerjoin(UserContext, RequestedUser.username == UserContext.username)
.filter(UserContext.username == None)
.all()
)
for user in missing_users:
logging.info(f"Missing user: {user.username}")
db.session.query(RequestedUser).filter_by(username=user.username).delete()
db.session.commit()


@app.before_request
def before_request():
Expand Down Expand Up @@ -181,20 +192,6 @@ def static_files(filename):
return send_from_directory("static", filename)


@app.before_first_request
def delete_missing_users():
with app.app_context():
missing_users = (
db.session.query(RequestedUser)
.outerjoin(UserContext, RequestedUser.username == UserContext.username)
.filter(UserContext.username == None)
.all()
)
for user in missing_users:
logging.info(f"Missing user: {user.username}")
db.session.query(RequestedUser).filter_by(username=user.username).delete()
db.session.commit()


if __name__ == "__main__":
app.run(host="0.0.0.0", port=5000)

0 comments on commit 5b971ee

Please sign in to comment.