try to fix insert

This commit is contained in:
2025-06-05 11:52:39 +02:00
parent d4ae0fe2d8
commit ee5b2d9fd9
2 changed files with 29 additions and 10 deletions

Binary file not shown.

View File

@@ -175,6 +175,7 @@ class DocuPulseSettings(db.Model):
@classmethod
def get_settings(cls):
try:
settings = cls.query.first()
if not settings:
settings = cls(
@@ -185,10 +186,28 @@ class DocuPulseSettings(db.Model):
db.session.add(settings)
db.session.commit()
return settings
except Exception as e:
# If there's an error (like integer overflow), rollback and return None
db.session.rollback()
return None
@classmethod
def get_usage_stats(cls):
settings = cls.get_settings()
if not settings:
# Return default values if settings can't be retrieved
return {
'max_rooms': 10,
'max_conversations': 10,
'max_storage': 10737418240,
'current_rooms': 0,
'current_conversations': 0,
'current_storage': 0,
'rooms_percentage': 0,
'conversations_percentage': 0,
'storage_percentage': 0
}
total_rooms = Room.query.count()
total_conversations = Conversation.query.count()
total_storage = db.session.query(db.func.sum(RoomFile.size)).filter(RoomFile.deleted == False).scalar() or 0