diff --git a/webapp/titanembeds/app.py b/webapp/titanembeds/app.py index 77ff353..25e83a3 100644 --- a/webapp/titanembeds/app.py +++ b/webapp/titanembeds/app.py @@ -28,6 +28,7 @@ app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False # Suppress the warning/no app.config['RATELIMIT_HEADERS_ENABLED'] = True app.config['SQLALCHEMY_POOL_RECYCLE'] = 250 app.config['SQLALCHEMY_POOL_SIZE'] = 100 +app.config['SQLALCHEMY_COMMIT_ON_TEARDOWN'] = True app.config['RATELIMIT_STORAGE_URL'] = config["redis-uri"] app.config['PERMANENT_SESSION_LIFETIME'] = timedelta(days=3) app.config['REDIS_URL'] = config["redis-uri"] diff --git a/webapp/titanembeds/blueprints/admin/admin.py b/webapp/titanembeds/blueprints/admin/admin.py index ad01f01..deb8543 100644 --- a/webapp/titanembeds/blueprints/admin/admin.py +++ b/webapp/titanembeds/blueprints/admin/admin.py @@ -67,7 +67,6 @@ def cosmetics_post(): badges = [] user.badges = json.dumps(badges) db.session.add(user) - db.session.commit() return ('', 204) @admin.route("/cosmetics", methods=["DELETE"]) @@ -80,7 +79,6 @@ def cosmetics_delete(): if not entry: abort(409) db.session.delete(entry) - db.session.commit() return ('', 204) @admin.route("/cosmetics", methods=["PATCH"]) @@ -109,7 +107,6 @@ def cosmetics_patch(): if badges == [""]: badges = [] entry.badges = json.dumps(badges) - db.session.commit() return ('', 204) def prepare_guild_members_list(members, bans): @@ -202,7 +199,6 @@ def update_administrate_guild(guild_id): if guest_icon != None and guest_icon.strip() == "": guest_icon = None db_guild.guest_icon = guest_icon - db.session.commit() emit("guest_icon_change", {"guest_icon": guest_icon if guest_icon else url_for('static', filename='img/titanembeds_square.png')}, room="GUILD_"+guild_id, namespace="/gateway") return jsonify( id=db_guild.id, @@ -288,7 +284,6 @@ def post_disabled_guilds(): abort(409) guild = DisabledGuilds(guild_id) db.session.add(guild) - db.session.commit() return ('', 204) @admin.route("/disabled_guilds", methods=["DELETE"]) @@ -299,7 +294,6 @@ def delete_disabled_guilds(): abort(409) guild = db.session.query(DisabledGuilds).filter(DisabledGuilds.guild_id == guild_id).first() db.session.delete(guild) - db.session.commit() return ('', 204) @admin.route("/custom_css", methods=["GET"]) @@ -344,7 +338,6 @@ def edit_custom_css_post(css_id): dbcss.css = css dbcss.css_variables = variables dbcss.css_var_bool = variables_enabled - db.session.commit() return jsonify({"id": dbcss.id}) @admin.route("/custom_css/edit/", methods=["DELETE"]) @@ -354,7 +347,6 @@ def edit_custom_css_delete(css_id): if not dbcss: abort(404) db.session.delete(dbcss) - db.session.commit() return jsonify({}) @admin.route("/custom_css/new", methods=["GET"]) @@ -381,5 +373,4 @@ def new_custom_css_post(): css = None css = UserCSS(name, user_id, variables_enabled, variables, css) db.session.add(css) - db.session.commit() return jsonify({"id": css.id}) \ No newline at end of file diff --git a/webapp/titanembeds/blueprints/api/api.py b/webapp/titanembeds/blueprints/api/api.py index adaf415..a9fa7a2 100644 --- a/webapp/titanembeds/blueprints/api/api.py +++ b/webapp/titanembeds/blueprints/api/api.py @@ -313,7 +313,6 @@ def create_unauthenticated_user(): session['user_id'] = random.randint(0,9999) user = UnauthenticatedUsers(guild_id, username, session['user_id'], ip_address) db.session.add(user) - db.session.commit() key = user.user_key if 'user_keys' not in session: session['user_keys'] = {guild_id: key} @@ -353,7 +352,6 @@ def change_unauthenticated_username(): session['user_id'] = random.randint(0,9999) user = UnauthenticatedUsers(guild_id, username, session['user_id'], ip_address) db.session.add(user) - db.session.commit() key = user.user_key session['user_keys'][guild_id] = key status = update_user_status(guild_id, username, key) @@ -428,7 +426,6 @@ def create_authenticated_user(): if not db_user: db_user = AuthenticatedUsers(guild_id, session['user_id']) db.session.add(db_user) - db.session.commit() status = update_user_status(guild_id, session['username']) return jsonify(status=status) else: diff --git a/webapp/titanembeds/blueprints/user/user.py b/webapp/titanembeds/blueprints/user/user.py index 3e6f198..1fa66a1 100644 --- a/webapp/titanembeds/blueprints/user/user.py +++ b/webapp/titanembeds/blueprints/user/user.py @@ -119,7 +119,6 @@ def new_custom_css_post(): css = None css = UserCSS(name, user_id, variables_enabled, variables, css) db.session.add(css) - db.session.commit() return jsonify({"id": css.id}) @user.route("/custom_css/edit/", methods=["GET"]) @@ -165,7 +164,6 @@ def edit_custom_css_post(css_id): dbcss.css = css dbcss.css_variables = variables dbcss.css_var_bool = variables_enabled - db.session.commit() return jsonify({"id": dbcss.id}) @user.route("/custom_css/edit/", methods=["DELETE"]) @@ -180,7 +178,6 @@ def edit_custom_css_delete(css_id): if dbcss.user_id != session['user_id']: abort(403) db.session.delete(dbcss) - db.session.commit() return jsonify({}) @user.route("/administrate_guild/", methods=["GET"]) @@ -250,7 +247,6 @@ def update_administrate_guild(guild_id): guest_icon = None db_guild.guest_icon = guest_icon - db.session.commit() emit("guest_icon_change", {"guest_icon": guest_icon if guest_icon else url_for('static', filename='img/titanembeds_square.png')}, room="GUILD_"+guild_id, namespace="/gateway") return jsonify( id=db_guild.id, @@ -337,7 +333,6 @@ def ban_unauthenticated_user(): db.session.delete(db_ban) db_ban = UnauthenticatedBans(guild_id, db_user.ip_address, db_user.username, db_user.discriminator, reason, session["user_id"]) db.session.add(db_ban) - db.session.commit() return ('', 204) @user.route("/ban", methods=["DELETE"]) @@ -481,7 +476,6 @@ def donate_patch(): entry = Cosmetics(session["user_id"]) entry.guest_icon = True db.session.add(entry) - db.session.commit() return ('', 204) @user.route("/patreon") @@ -561,7 +555,6 @@ def patreon_sync_post(): dbpatreon = Patreon(usr["id"]) dbpatreon.total_synced = usr["titan"]["total_cents_pledged"] db.session.add(dbpatreon) - db.session.commit() set_titan_token(session["user_id"], usr["titan"]["eligible_tokens"], "PATREON {} [{}]".format(usr["attributes"]["full_name"], usr["id"])) add_badge(session["user_id"], "supporter") session["tokens"] = get_titan_token(session["user_id"]) diff --git a/webapp/titanembeds/database/__init__.py b/webapp/titanembeds/database/__init__.py index 7f751bd..6c5c6df 100644 --- a/webapp/titanembeds/database/__init__.py +++ b/webapp/titanembeds/database/__init__.py @@ -30,5 +30,4 @@ def set_titan_token(user_id, amt_change, action): db.session.add(transact) token_usr.tokens = new_token_count db.session.add(token_usr) - db.session.commit() return True \ No newline at end of file diff --git a/webapp/titanembeds/database/cosmetics.py b/webapp/titanembeds/database/cosmetics.py index 4a615c1..21b149a 100644 --- a/webapp/titanembeds/database/cosmetics.py +++ b/webapp/titanembeds/database/cosmetics.py @@ -39,7 +39,6 @@ def set_badges(user_id, badges): usr = Cosmetics(user_id) usr.badges = json.dumps(badges) db.session.add(usr) - db.session.commit() def get_badges(user_id): usr = db.session.query(Cosmetics).filter(Cosmetics.user_id == user_id).first() diff --git a/webapp/titanembeds/database/guilds.py b/webapp/titanembeds/database/guilds.py index 13741b5..8957f16 100644 --- a/webapp/titanembeds/database/guilds.py +++ b/webapp/titanembeds/database/guilds.py @@ -44,5 +44,4 @@ class Guilds(db.Model): def set_unauthUsersBool(self, value): self.unauth_users = value - db.session.commit() return self.unauth_users diff --git a/webapp/titanembeds/database/unauthenticated_bans.py b/webapp/titanembeds/database/unauthenticated_bans.py index 47800d8..7160f41 100644 --- a/webapp/titanembeds/database/unauthenticated_bans.py +++ b/webapp/titanembeds/database/unauthenticated_bans.py @@ -26,7 +26,6 @@ class UnauthenticatedBans(db.Model): def liftBan(self, lifter_id): self.lifter_id = lifter_id - db.session.commit() return self.lifter_id def __repr__(self): diff --git a/webapp/titanembeds/database/unauthenticated_users.py b/webapp/titanembeds/database/unauthenticated_users.py index 75470a3..6989d66 100644 --- a/webapp/titanembeds/database/unauthenticated_users.py +++ b/webapp/titanembeds/database/unauthenticated_users.py @@ -30,10 +30,8 @@ class UnauthenticatedUsers(db.Model): def changeUsername(self, username): self.username = username - db.session.commit() return self.username def revokeUser(self): self.revoked = True - db.session.commit() return self.revoked diff --git a/webapp/titanembeds/utils.py b/webapp/titanembeds/utils.py index fd1bb9c..7ba62fc 100644 --- a/webapp/titanembeds/utils.py +++ b/webapp/titanembeds/utils.py @@ -142,7 +142,6 @@ def update_user_status(guild_id, username, user_key=None): if dbUser.username != username or dbUser.ip_address != ip_address: dbUser.username = username dbUser.ip_address = ip_address - db.session.commit() else: status = { 'authenticated': True,