Feature/file manager#10
Merged
Merged
Conversation
Refactor and improve code quality
This commit includes several code improvements and refactorings:
1. **Refactored `app/core/models.py` for log counting:**
* Introduced a private helper method `_count_logs_since` in the `SystemLog` model to consolidate logic for counting logs based on time, level, and security status.
* Updated `get_error_count_last_24h` and `get_security_events_count_last_24h` to use this new helper method, reducing code duplication.
2. **Made security log retention configurable:**
* Added a `SECURITY_LOG_RETENTION_DAYS` configuration variable in `app/config.py` (defaulting to 90 days, settable via environment variable).
* Modified the `cleanup_old_logs` method in `SystemLog` to use this configuration value instead of a hardcoded one.
3. **Improved `app/core/models.py` documentation and readability:**
* Added a docstring to `LogSearchQuery.to_dict()`.
* Ensured dictionary definitions and SQLAlchemy queries in `SystemLog` methods are formatted for better readability.
* Removed some redundant local imports of `datetime` and `timedelta`.
4. **Refactored exception handling in `app/auth/routes.py`:**
* Introduced a private helper function `_handle_auth_exception` to standardize logging and flash messages for exceptions occurring during user login and registration.
* Updated the `login` and `register` routes to use this helper, reducing boilerplate.
These changes aim to improve code maintainability, readability, and configurability.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Refactor and improve code quality
This commit includes several code improvements and refactorings:
Refactored
app/core/models.pyfor log counting:_count_logs_sincein theSystemLogmodel to consolidate logic for counting logs based on time, level, and security status.get_error_count_last_24handget_security_events_count_last_24hto use this new helper method, reducing code duplication.Made security log retention configurable:
SECURITY_LOG_RETENTION_DAYSconfiguration variable inapp/config.py(defaulting to 90 days, settable via environment variable).cleanup_old_logsmethod inSystemLogto use this configuration value instead of a hardcoded one.Improved
app/core/models.pydocumentation and readability:LogSearchQuery.to_dict().SystemLogmethods are formatted for better readability.datetimeandtimedelta.Refactored exception handling in
app/auth/routes.py:_handle_auth_exceptionto standardize logging and flash messages for exceptions occurring during user login and registration.loginandregisterroutes to use this helper, reducing boilerplate.Also default terminal path changed to /home/$USER