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