mirror of
https://gitlab.com/crafty-controller/crafty-4.git
synced 2024-08-30 18:23:09 +00:00
Merge branch 'revert-d0b17c8d' into 'dev'
Revert "Merge branch 'bug/DB_Lock' into 'dev'" See merge request crafty-controller/crafty-commander!243
This commit is contained in:
commit
d78d51d091
@ -6,6 +6,7 @@ from app.classes.models.users import Users, ApiKeys, users_helper
|
|||||||
|
|
||||||
try:
|
try:
|
||||||
from peewee import (
|
from peewee import (
|
||||||
|
SqliteDatabase,
|
||||||
Model,
|
Model,
|
||||||
ForeignKeyField,
|
ForeignKeyField,
|
||||||
CharField,
|
CharField,
|
||||||
@ -13,7 +14,6 @@ try:
|
|||||||
DoesNotExist,
|
DoesNotExist,
|
||||||
)
|
)
|
||||||
from enum import Enum
|
from enum import Enum
|
||||||
from playhouse.sqliteq import SqliteQueueDatabase
|
|
||||||
|
|
||||||
except ModuleNotFoundError as e:
|
except ModuleNotFoundError as e:
|
||||||
helper.auto_installer_fix(e)
|
helper.auto_installer_fix(e)
|
||||||
@ -21,9 +21,8 @@ except ModuleNotFoundError as e:
|
|||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
peewee_logger = logging.getLogger("peewee")
|
peewee_logger = logging.getLogger("peewee")
|
||||||
peewee_logger.setLevel(logging.INFO)
|
peewee_logger.setLevel(logging.INFO)
|
||||||
database = SqliteQueueDatabase(
|
database = SqliteDatabase(
|
||||||
helper.db_path
|
helper.db_path, pragmas={"journal_mode": "wal", "cache_size": -1024 * 10}
|
||||||
# pragmas={"journal_mode": "wal", "cache_size": -1024 * 10}
|
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
@ -10,6 +10,7 @@ from app.classes.web.websocket_helper import websocket_helper
|
|||||||
|
|
||||||
try:
|
try:
|
||||||
from peewee import (
|
from peewee import (
|
||||||
|
SqliteDatabase,
|
||||||
Model,
|
Model,
|
||||||
ForeignKeyField,
|
ForeignKeyField,
|
||||||
CharField,
|
CharField,
|
||||||
@ -21,7 +22,6 @@ try:
|
|||||||
BooleanField,
|
BooleanField,
|
||||||
)
|
)
|
||||||
from playhouse.shortcuts import model_to_dict
|
from playhouse.shortcuts import model_to_dict
|
||||||
from playhouse.sqliteq import SqliteQueueDatabase
|
|
||||||
|
|
||||||
except ModuleNotFoundError as e:
|
except ModuleNotFoundError as e:
|
||||||
helper.auto_installer_fix(e)
|
helper.auto_installer_fix(e)
|
||||||
@ -29,9 +29,8 @@ except ModuleNotFoundError as e:
|
|||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
peewee_logger = logging.getLogger("peewee")
|
peewee_logger = logging.getLogger("peewee")
|
||||||
peewee_logger.setLevel(logging.INFO)
|
peewee_logger.setLevel(logging.INFO)
|
||||||
database = SqliteQueueDatabase(
|
database = SqliteDatabase(
|
||||||
helper.db_path
|
helper.db_path, pragmas={"journal_mode": "wal", "cache_size": -1024 * 10}
|
||||||
# pragmas={"journal_mode": "wal", "cache_size": -1024 * 10}
|
|
||||||
)
|
)
|
||||||
|
|
||||||
# **********************************************************************************
|
# **********************************************************************************
|
||||||
@ -382,24 +381,28 @@ class helpers_management:
|
|||||||
conf["excluded_dirs"] = dirs_to_exclude
|
conf["excluded_dirs"] = dirs_to_exclude
|
||||||
conf["compress"] = compress
|
conf["compress"] = compress
|
||||||
if not new_row:
|
if not new_row:
|
||||||
if backup_path is not None:
|
with database.atomic():
|
||||||
u1 = (
|
if backup_path is not None:
|
||||||
Servers.update(backup_path=backup_path)
|
u1 = (
|
||||||
.where(Servers.server_id == server_id)
|
Servers.update(backup_path=backup_path)
|
||||||
.execute()
|
.where(Servers.server_id == server_id)
|
||||||
|
.execute()
|
||||||
|
)
|
||||||
|
else:
|
||||||
|
u1 = 0
|
||||||
|
u2 = (
|
||||||
|
Backups.update(conf).where(Backups.server_id == server_id).execute()
|
||||||
)
|
)
|
||||||
else:
|
|
||||||
u1 = 0
|
|
||||||
u2 = Backups.update(conf).where(Backups.server_id == server_id).execute()
|
|
||||||
logger.debug(f"Updating existing backup record. {u1}+{u2} rows affected")
|
logger.debug(f"Updating existing backup record. {u1}+{u2} rows affected")
|
||||||
else:
|
else:
|
||||||
conf["server_id"] = server_id
|
with database.atomic():
|
||||||
if backup_path is not None:
|
conf["server_id"] = server_id
|
||||||
Servers.update(backup_path=backup_path).where(
|
if backup_path is not None:
|
||||||
Servers.server_id == server_id
|
Servers.update(backup_path=backup_path).where(
|
||||||
)
|
Servers.server_id == server_id
|
||||||
Backups.create(**conf)
|
)
|
||||||
logger.debug("Creating new backup record.")
|
Backups.create(**conf)
|
||||||
|
logger.debug("Creating new backup record.")
|
||||||
|
|
||||||
def get_excluded_backup_dirs(self, server_id: int):
|
def get_excluded_backup_dirs(self, server_id: int):
|
||||||
excluded_dirs = self.get_backup_config(server_id)["excluded_dirs"]
|
excluded_dirs = self.get_backup_config(server_id)["excluded_dirs"]
|
||||||
|
@ -5,6 +5,7 @@ from app.classes.shared.helpers import helper
|
|||||||
|
|
||||||
try:
|
try:
|
||||||
from peewee import (
|
from peewee import (
|
||||||
|
SqliteDatabase,
|
||||||
Model,
|
Model,
|
||||||
CharField,
|
CharField,
|
||||||
DoesNotExist,
|
DoesNotExist,
|
||||||
@ -12,7 +13,6 @@ try:
|
|||||||
DateTimeField,
|
DateTimeField,
|
||||||
)
|
)
|
||||||
from playhouse.shortcuts import model_to_dict
|
from playhouse.shortcuts import model_to_dict
|
||||||
from playhouse.sqliteq import SqliteQueueDatabase
|
|
||||||
|
|
||||||
except ModuleNotFoundError as e:
|
except ModuleNotFoundError as e:
|
||||||
helper.auto_installer_fix(e)
|
helper.auto_installer_fix(e)
|
||||||
@ -20,9 +20,8 @@ except ModuleNotFoundError as e:
|
|||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
peewee_logger = logging.getLogger("peewee")
|
peewee_logger = logging.getLogger("peewee")
|
||||||
peewee_logger.setLevel(logging.INFO)
|
peewee_logger.setLevel(logging.INFO)
|
||||||
database = SqliteQueueDatabase(
|
database = SqliteDatabase(
|
||||||
helper.db_path
|
helper.db_path, pragmas={"journal_mode": "wal", "cache_size": -1024 * 10}
|
||||||
# pragmas={"journal_mode": "wal", "cache_size": -1024 * 10}
|
|
||||||
)
|
)
|
||||||
|
|
||||||
# **********************************************************************************
|
# **********************************************************************************
|
||||||
@ -75,8 +74,9 @@ class helper_roles:
|
|||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def remove_role(role_id):
|
def remove_role(role_id):
|
||||||
role = Roles.get(Roles.role_id == role_id)
|
with database.atomic():
|
||||||
return role.delete_instance()
|
role = Roles.get(Roles.role_id == role_id)
|
||||||
|
return role.delete_instance()
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def role_id_exists(role_id):
|
def role_id_exists(role_id):
|
||||||
|
@ -8,6 +8,7 @@ from app.classes.shared.permission_helper import permission_helper
|
|||||||
|
|
||||||
try:
|
try:
|
||||||
from peewee import (
|
from peewee import (
|
||||||
|
SqliteDatabase,
|
||||||
Model,
|
Model,
|
||||||
ForeignKeyField,
|
ForeignKeyField,
|
||||||
CharField,
|
CharField,
|
||||||
@ -15,7 +16,6 @@ try:
|
|||||||
JOIN,
|
JOIN,
|
||||||
)
|
)
|
||||||
from enum import Enum
|
from enum import Enum
|
||||||
from playhouse.sqliteq import SqliteQueueDatabase
|
|
||||||
|
|
||||||
except ModuleNotFoundError as e:
|
except ModuleNotFoundError as e:
|
||||||
helper.auto_installer_fix(e)
|
helper.auto_installer_fix(e)
|
||||||
@ -23,9 +23,8 @@ except ModuleNotFoundError as e:
|
|||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
peewee_logger = logging.getLogger("peewee")
|
peewee_logger = logging.getLogger("peewee")
|
||||||
peewee_logger.setLevel(logging.INFO)
|
peewee_logger.setLevel(logging.INFO)
|
||||||
database = SqliteQueueDatabase(
|
database = SqliteDatabase(
|
||||||
helper.db_path
|
helper.db_path, pragmas={"journal_mode": "wal", "cache_size": -1024 * 10}
|
||||||
# pragmas={"journal_mode": "wal", "cache_size": -1024 * 10}
|
|
||||||
)
|
)
|
||||||
|
|
||||||
# **********************************************************************************
|
# **********************************************************************************
|
||||||
@ -194,9 +193,12 @@ class Permissions_Servers:
|
|||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def remove_roles_of_server(server_id):
|
def remove_roles_of_server(server_id):
|
||||||
return (
|
with database.atomic():
|
||||||
Role_Servers.delete().where(Role_Servers.server_id == server_id).execute()
|
return (
|
||||||
)
|
Role_Servers.delete()
|
||||||
|
.where(Role_Servers.server_id == server_id)
|
||||||
|
.execute()
|
||||||
|
)
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def get_user_id_permissions_mask(user_id, server_id: str):
|
def get_user_id_permissions_mask(user_id, server_id: str):
|
||||||
|
@ -6,6 +6,7 @@ from app.classes.shared.main_models import db_helper
|
|||||||
|
|
||||||
try:
|
try:
|
||||||
from peewee import (
|
from peewee import (
|
||||||
|
SqliteDatabase,
|
||||||
Model,
|
Model,
|
||||||
ForeignKeyField,
|
ForeignKeyField,
|
||||||
CharField,
|
CharField,
|
||||||
@ -15,7 +16,6 @@ try:
|
|||||||
IntegerField,
|
IntegerField,
|
||||||
FloatField,
|
FloatField,
|
||||||
)
|
)
|
||||||
from playhouse.sqliteq import SqliteQueueDatabase
|
|
||||||
|
|
||||||
except ModuleNotFoundError as e:
|
except ModuleNotFoundError as e:
|
||||||
helper.auto_installer_fix(e)
|
helper.auto_installer_fix(e)
|
||||||
@ -23,9 +23,8 @@ except ModuleNotFoundError as e:
|
|||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
peewee_logger = logging.getLogger("peewee")
|
peewee_logger = logging.getLogger("peewee")
|
||||||
peewee_logger.setLevel(logging.INFO)
|
peewee_logger.setLevel(logging.INFO)
|
||||||
database = SqliteQueueDatabase(
|
database = SqliteDatabase(
|
||||||
helper.db_path
|
helper.db_path, pragmas={"journal_mode": "wal", "cache_size": -1024 * 10}
|
||||||
# pragmas={"journal_mode": "wal", "cache_size": -1024 * 10}
|
|
||||||
)
|
)
|
||||||
|
|
||||||
# **********************************************************************************
|
# **********************************************************************************
|
||||||
@ -142,7 +141,8 @@ class helper_servers:
|
|||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def remove_server(server_id):
|
def remove_server(server_id):
|
||||||
Servers.delete().where(Servers.server_id == server_id).execute()
|
with database.atomic():
|
||||||
|
Servers.delete().where(Servers.server_id == server_id).execute()
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def get_server_data_by_id(server_id):
|
def get_server_data_by_id(server_id):
|
||||||
@ -224,21 +224,24 @@ class helper_servers:
|
|||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def sever_crashed(server_id):
|
def sever_crashed(server_id):
|
||||||
Server_Stats.update(crashed=True).where(
|
with database.atomic():
|
||||||
Server_Stats.server_id == server_id
|
Server_Stats.update(crashed=True).where(
|
||||||
).execute()
|
Server_Stats.server_id == server_id
|
||||||
|
).execute()
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def set_download(server_id):
|
def set_download(server_id):
|
||||||
Server_Stats.update(downloading=True).where(
|
with database.atomic():
|
||||||
Server_Stats.server_id == server_id
|
Server_Stats.update(downloading=True).where(
|
||||||
).execute()
|
Server_Stats.server_id == server_id
|
||||||
|
).execute()
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def finish_download(server_id):
|
def finish_download(server_id):
|
||||||
Server_Stats.update(downloading=False).where(
|
with database.atomic():
|
||||||
Server_Stats.server_id == server_id
|
Server_Stats.update(downloading=False).where(
|
||||||
).execute()
|
Server_Stats.server_id == server_id
|
||||||
|
).execute()
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def get_download_status(server_id):
|
def get_download_status(server_id):
|
||||||
@ -249,9 +252,10 @@ class helper_servers:
|
|||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def server_crash_reset(server_id):
|
def server_crash_reset(server_id):
|
||||||
Server_Stats.update(crashed=False).where(
|
with database.atomic():
|
||||||
Server_Stats.server_id == server_id
|
Server_Stats.update(crashed=False).where(
|
||||||
).execute()
|
Server_Stats.server_id == server_id
|
||||||
|
).execute()
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def is_crashed(server_id):
|
def is_crashed(server_id):
|
||||||
@ -268,9 +272,10 @@ class helper_servers:
|
|||||||
Server_Stats.select().where(Server_Stats.server_id == server_id)
|
Server_Stats.select().where(Server_Stats.server_id == server_id)
|
||||||
except Exception as ex:
|
except Exception as ex:
|
||||||
logger.error(f"Database entry not found! {ex}")
|
logger.error(f"Database entry not found! {ex}")
|
||||||
Server_Stats.update(updating=value).where(
|
with database.atomic():
|
||||||
Server_Stats.server_id == server_id
|
Server_Stats.update(updating=value).where(
|
||||||
).execute()
|
Server_Stats.server_id == server_id
|
||||||
|
).execute()
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def get_update_status(server_id):
|
def get_update_status(server_id):
|
||||||
@ -288,9 +293,10 @@ class helper_servers:
|
|||||||
except Exception as ex:
|
except Exception as ex:
|
||||||
logger.error(f"Database entry not found! {ex}")
|
logger.error(f"Database entry not found! {ex}")
|
||||||
return
|
return
|
||||||
Server_Stats.update(first_run=False).where(
|
with database.atomic():
|
||||||
Server_Stats.server_id == server_id
|
Server_Stats.update(first_run=False).where(
|
||||||
).execute()
|
Server_Stats.server_id == server_id
|
||||||
|
).execute()
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def get_first_run(server_id):
|
def get_first_run(server_id):
|
||||||
@ -331,9 +337,10 @@ class helper_servers:
|
|||||||
Server_Stats.select().where(Server_Stats.server_id == server_id)
|
Server_Stats.select().where(Server_Stats.server_id == server_id)
|
||||||
except Exception as ex:
|
except Exception as ex:
|
||||||
logger.error(f"Database entry not found! {ex}")
|
logger.error(f"Database entry not found! {ex}")
|
||||||
Server_Stats.update(waiting_start=value).where(
|
with database.atomic():
|
||||||
Server_Stats.server_id == server_id
|
Server_Stats.update(waiting_start=value).where(
|
||||||
).execute()
|
Server_Stats.server_id == server_id
|
||||||
|
).execute()
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def get_waiting_start(server_id):
|
def get_waiting_start(server_id):
|
||||||
|
@ -7,6 +7,7 @@ from app.classes.shared.helpers import helper
|
|||||||
|
|
||||||
try:
|
try:
|
||||||
from peewee import (
|
from peewee import (
|
||||||
|
SqliteDatabase,
|
||||||
Model,
|
Model,
|
||||||
ForeignKeyField,
|
ForeignKeyField,
|
||||||
CharField,
|
CharField,
|
||||||
@ -18,7 +19,6 @@ try:
|
|||||||
JOIN,
|
JOIN,
|
||||||
)
|
)
|
||||||
from playhouse.shortcuts import model_to_dict
|
from playhouse.shortcuts import model_to_dict
|
||||||
from playhouse.sqliteq import SqliteQueueDatabase
|
|
||||||
|
|
||||||
except ModuleNotFoundError as e:
|
except ModuleNotFoundError as e:
|
||||||
helper.auto_installer_fix(e)
|
helper.auto_installer_fix(e)
|
||||||
@ -26,9 +26,8 @@ except ModuleNotFoundError as e:
|
|||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
peewee_logger = logging.getLogger("peewee")
|
peewee_logger = logging.getLogger("peewee")
|
||||||
peewee_logger.setLevel(logging.INFO)
|
peewee_logger.setLevel(logging.INFO)
|
||||||
database = SqliteQueueDatabase(
|
database = SqliteDatabase(
|
||||||
helper.db_path
|
helper.db_path, pragmas={"journal_mode": "wal", "cache_size": -1024 * 10}
|
||||||
# pragmas={"journal_mode": "wal", "cache_size": -1024 * 10}
|
|
||||||
)
|
)
|
||||||
|
|
||||||
# **********************************************************************************
|
# **********************************************************************************
|
||||||
@ -233,9 +232,10 @@ class helper_users:
|
|||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def remove_user(user_id):
|
def remove_user(user_id):
|
||||||
User_Roles.delete().where(User_Roles.user_id == user_id).execute()
|
with database.atomic():
|
||||||
user = Users.get(Users.user_id == user_id)
|
User_Roles.delete().where(User_Roles.user_id == user_id).execute()
|
||||||
return user.delete_instance()
|
user = Users.get(Users.user_id == user_id)
|
||||||
|
return user.delete_instance()
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def set_support_path(user_id, support_path):
|
def set_support_path(user_id, support_path):
|
||||||
|
@ -10,8 +10,7 @@ Users = Users
|
|||||||
|
|
||||||
try:
|
try:
|
||||||
# pylint: disable=unused-import
|
# pylint: disable=unused-import
|
||||||
from peewee import fn
|
from peewee import SqliteDatabase, fn
|
||||||
from playhouse.sqliteq import SqliteQueueDatabase
|
|
||||||
from playhouse.shortcuts import model_to_dict
|
from playhouse.shortcuts import model_to_dict
|
||||||
|
|
||||||
except ModuleNotFoundError as err:
|
except ModuleNotFoundError as err:
|
||||||
@ -20,7 +19,7 @@ except ModuleNotFoundError as err:
|
|||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
peewee_logger = logging.getLogger("peewee")
|
peewee_logger = logging.getLogger("peewee")
|
||||||
peewee_logger.setLevel(logging.INFO)
|
peewee_logger.setLevel(logging.INFO)
|
||||||
database = SqliteQueueDatabase(
|
database = SqliteDatabase(
|
||||||
helper.db_path
|
helper.db_path
|
||||||
# This is commented out after presenting issues when
|
# This is commented out after presenting issues when
|
||||||
# moving from SQLiteDatabase to SqliteQueueDatabase
|
# moving from SQLiteDatabase to SqliteQueueDatabase
|
||||||
|
Loading…
Reference in New Issue
Block a user