-
Notifications
You must be signed in to change notification settings - Fork 3
🐛 移除 julianday 的使用,兼容更多数据库 #550
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Codecov ReportAttention: Patch coverage is
🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR removes the use of SQLite-specific julianday
function and replaces it with database-agnostic date comparison logic to improve compatibility across different database systems. The change affects how the system finds comparison data points that are closest to 24 hours before the latest record.
- Replaced SQLite
julianday
function with standard datetime comparison using<=
and>=
operators - Implemented a two-query approach to find records before and after the target time, then select the closest one
- Added comprehensive Chinese comments explaining the logic flow
Reviewed Changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 4 comments.
File | Description |
---|---|
nonebot_plugin_tetris_stats/games/tetrio/rank/detail.py | Updated comparison data query logic to use database-agnostic datetime operations |
nonebot_plugin_tetris_stats/games/tetrio/rank/all.py | Applied the same database-agnostic datetime comparison logic |
.options(selectinload(TETRIOLeagueStats.fields)) | ||
) | ||
).one() | ||
or latest_data # 回退到最新记录 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The fallback logic using or latest_data
will always evaluate to latest_data
when the query returns None
, but this could lead to incorrect comparison calculations. Consider checking if valid comparison data exists before proceeding, or handle the case where no historical data is available more explicitly.
or latest_data # 回退到最新记录 | |
if before is None else before # Explicitly check for None |
Copilot uses AI. Check for mistakes.
.options(selectinload(TETRIOLeagueStats.fields)) | ||
) | ||
).one() | ||
or latest_data |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The fallback logic using or latest_data
will always evaluate to latest_data
when the query returns None
, but this could lead to incorrect comparison calculations. Consider checking if valid comparison data exists before proceeding, or handle the case where no historical data is available more explicitly.
Copilot uses AI. Check for mistakes.
compare_data = ( | ||
before | ||
if abs((target_time - before.update_time).total_seconds()) | ||
< abs((target_time - after.update_time).total_seconds()) | ||
else after | ||
) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When before
or after
fallback to latest_data
, the time difference calculation may not work as expected. If both queries return None and fallback to latest_data
, both before
and after
will reference the same object, making the comparison meaningless.
compare_data = ( | |
before | |
if abs((target_time - before.update_time).total_seconds()) | |
< abs((target_time - after.update_time).total_seconds()) | |
else after | |
) | |
if before is latest_data and after is latest_data: | |
compare_data = latest_data | |
else: | |
compare_data = ( | |
before | |
if abs((target_time - before.update_time).total_seconds()) | |
< abs((target_time - after.update_time).total_seconds()) | |
else after | |
) |
Copilot uses AI. Check for mistakes.
compare_data = ( | ||
before | ||
if abs((target_time - before.update_time).total_seconds()) | ||
< abs((target_time - after.update_time).total_seconds()) | ||
else after | ||
) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When before
or after
fallback to latest_data
, the time difference calculation may not work as expected. If both queries return None and fallback to latest_data
, both before
and after
will reference the same object, making the comparison meaningless.
compare_data = ( | |
before | |
if abs((target_time - before.update_time).total_seconds()) | |
< abs((target_time - after.update_time).total_seconds()) | |
else after | |
) | |
if before is latest_data and after is latest_data: | |
compare_data = latest_data | |
else: | |
compare_data = ( | |
before | |
if abs((target_time - before.update_time).total_seconds()) | |
< abs((target_time - after.update_time).total_seconds()) | |
else after | |
) |
Copilot uses AI. Check for mistakes.
No description provided.