Make add_or_update_user more efficient with upsert

This commit is contained in:
luukas 2022-05-16 17:15:46 +03:00
parent 8d2f4ba32e
commit d415c27a89

View File

@ -137,15 +137,9 @@ class PermissionsCrafty:
limit_user_creation,
limit_role_creation,
):
try:
user_crafty = UserCrafty.select().where(UserCrafty.user_id == user_id).get()
user_crafty.permissions = permissions_mask
user_crafty.limit_server_creation = limit_server_creation
user_crafty.limit_user_creation = limit_user_creation
user_crafty.limit_role_creation = limit_role_creation
UserCrafty.save(user_crafty)
except:
UserCrafty.insert(
# http://docs.peewee-orm.com/en/latest/peewee/querying.html#upsert
UserCrafty.replace(
{
UserCrafty.user_id: user_id,
UserCrafty.permissions: permissions_mask,