Hello, athletes!
Today we're releasing an important update that significantly improves the stability and reliability of the Peakline service. We've completely reworked the database system and added modern monitoring tools. This release solves critical performance issues and makes the service more resilient to load.
🗄️ Complete Database Work Refactoring
Problem solved: The service was suffering from database connection leaks and "Cannot operate on a closed database" errors, leading to unstable operation.
What changed:
* Database Context Manager: Replaced all direct sqlite3.connect()
calls with a safe context manager with get_db() as conn:
* Automatic Connection Management: All connections now automatically open and close, eliminating memory leaks
* Removed Middleware: Deleted outdated middleware that incorrectly managed database connections
* Timeouts to Prevent Deadlocks: Added timeout settings to avoid operation hanging
* Unified Approach: All system components now use the same database work pattern
Areas of changes: * Main application file * Token management system * Authentication modules * Telegram integration * Database abstraction layer
🏥 Service Health Monitoring System
New monitoring endpoints:
* /api/health
- basic health check for service status
* /api/health/db
- detailed database status check (protected by secret key)
Monitoring capabilities: * Database Connection Check: Automatic diagnosis of database availability and status * Service Information: Status, version, uptime * Security: Detailed information available only with correct secret key * Uptime Kuma Integration: Ready instructions for external monitoring setup
🔒 Security Improvements
Monitoring Protection: * Detailed database status information hidden from regular users * Secret key for access to extended diagnostics * Recommendations for secure external monitoring system setup
Security Audit: * Complete audit of all database-related components * Eliminated all potential vulnerabilities in user data handling * Verified correctness of all imports and dependencies
🚀 Performance and Stability
Before update: * Frequent "Cannot operate on a closed database" errors * Database connection leaks * Unstable operation under high load * No service status monitoring
After update: * Stable operation without database errors * Automatic resource management * Real-time monitoring capability * Quick problem identification and resolution
🛠️ Technical Details
Architectural Changes: * Implemented Repository pattern for data work * Context manager ensures RAII (Resource Acquisition Is Initialization) * Unified database error handling across all components
Monitoring: * RESTful API for health checks * JSON responses with detailed information * HTTP status codes for automatic monitoring * Support for various monitoring systems
📊 Impact on Users
Direct improvements: * Service became significantly more stable * Eliminated random data operation errors * Faster page loading due to database optimization * More reliable integration work (Telegram, Strava)
For administrators: * Ability to monitor service status * Quick problem identification * Diagnostic tools * Easy integration with external monitoring systems
🔄 Migration and Compatibility
Backward compatibility: * All existing API endpoints work without changes * User data remains untouched * Settings and configurations are preserved
Automatic update: * Update occurs automatically on service restart * No manual data migration required * All changes applied transparently
📋 What's Next
In future versions we plan to: * Add performance metrics to health check * Expand monitoring system for user activity tracking * Implement automatic alerts for critical issues * Add admin dashboard with service status visualization
🙏 Acknowledgments
Thank you to everyone who reported service stability issues! Your reports helped us identify and fix critical database problems.
P.S. If you notice any service operation issues - we now have reliable tools for quick diagnosis and problem resolution!