friends42
friends42 copied to clipboard
Implement JSON Import Feature, Enhance Database Transactions, and Dockerize the Application
Description
This merge request introduces several key enhancements to the application, including a robust JSON import feature with real-time status tracking, improved database transaction management, and full Dockerization for streamlined deployment. These updates aim to enhance user experience, ensure data integrity, and simplify the deployment process.
1. JSON Import Feature with Status Tracking
-
Functionality:
- Users can now import their settings via a JSON file through the profile settings page.
- The import process supports real-time status updates, allowing users to monitor the progress of their import even if they refresh the page.
-
Implementation Details:
-
Frontend Enhancements:
- Added file input and associated buttons for uploading JSON files.
- Utilized
sessionStorageto persist the import task ID, ensuring the import status remains visible across page refreshes. - Implemented JavaScript functions to handle file reading, validation, submission, and periodic status polling every 10 seconds.
- Displayed import status messages and disabled the import button during active imports to prevent duplicate tasks.
-
Backend Enhancements:
- Created new API endpoints
/settings/import_jsonand/settings/import_status/<task_id>to handle import requests and status checks. - Implemented a task queue and worker thread to process import tasks asynchronously, ensuring the main application remains responsive.
- Utilized SQL transactions to maintain data integrity during the import process, ensuring that all related database operations either complete successfully or are rolled back in case of errors.
- Created new API endpoints
-
2. Enhanced Database Transaction Management
-
Functionality:
- Improved the
Dbclass to use consistent attribute naming (self.conninstead of mixedself.connandself.con), eliminating attribute errors. - Ensured that each thread or request handler creates its own instance of the
Dbclass to prevent concurrent access issues with SQLite. - Incorporated context managers (
with Db(...) as db:) to manage database connections and transactions safely, automatically handling commits and rollbacks.
- Improved the
-
Implementation Details:
- Refactored the
Dbclass to standardize the connection attribute and ensure all methods correctly referenceself.conn. - Updated all routes and worker threads to instantiate the
Dbclass within their execution context, promoting thread safety and preventing shared connection conflicts. - Added retry mechanisms for database operations prone to locking issues, enhancing the robustness of database interactions.
- Refactored the
3. Dockerization of the Application
-
Functionality:
- Containerized the entire application using Docker to facilitate consistent environments across development, testing, and production.
- Simplified the setup process with Docker Compose, allowing for easy orchestration of multiple services such as the Flask application and the SQLite database.
-
Implementation Details:
-
Dockerfile:
- Created a
Dockerfileto define the application's Docker image, specifying the base image, dependencies, environment variables, and startup commands.
- Created a
-
Docker Compose:
- Developed a
docker-compose.ymlfile to manage multi-container configurations, including the Flask app and any auxiliary services. - Configured volume mounts for persistent storage of the SQLite database and static files. Exposed necessary ports to allow external access to the application.
- Developed a
-
Configuration Adjustments:
- Updated application configurations to accommodate running within Docker containers, such as setting appropriate environment variables and network settings.
- Ensured that the database file is correctly referenced within the Docker environment.
-
Additional Notes
-
Documentation:
- Update the project’s README and deployment guides to include instructions on using Docker and the new JSON import feature.
-
Proxy:
- Rebind proxy image in
routes/helpers.py, fromhttps://friends42.fr/proxy/tohttps://friends.42paris.fr/proxy/.
- Rebind proxy image in