Skip to content

fix: 月次ログが送信されない問題を修正#217

Merged
kashu-02 merged 1 commit intomasterfrom
reafactor-202512
Feb 3, 2026
Merged

fix: 月次ログが送信されない問題を修正#217
kashu-02 merged 1 commit intomasterfrom
reafactor-202512

Conversation

@kashu-02
Copy link
Member

@kashu-02 kashu-02 commented Feb 3, 2026

This pull request updates the logic for exporting and processing user log data, focusing on improving the accuracy of room entry/exit tracking and standardizing identifiers in the CSV export functionality. The main changes involve refining SQL queries to correctly identify users' latest room status, replacing ambiguous identifiers, and improving code readability.

Database query and logic improvements:

  • Updated the SQL query in ForceLeave to select only users whose most recent log entry before a given time indicates they are still in the room, improving the accuracy of force-leave operations.

CSV export and identifier standardization:

  • Changed CSV export queries and code to use ainsID instead of sid for user identification, ensuring consistency with the database schema. [1] [2] [3]
  • Introduced a named constant Enter for the enter/leave status to improve code readability and maintainability.

Code style and consistency:

  • Standardized SQL keywords to uppercase in the log deletion statement for consistency.

@kashu-02 kashu-02 self-assigned this Feb 3, 2026
Copilot AI review requested due to automatic review settings February 3, 2026 08:35
@kashu-02 kashu-02 merged commit 3f90e54 into master Feb 3, 2026
5 of 7 checks passed
Copy link
Contributor

Copilot AI left a 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 pull request addresses an issue with monthly log exports by improving the accuracy of room entry/exit tracking and standardizing database identifiers throughout the codebase. The changes migrate from using sid to ainsID for user identification, which aligns with the actual database schema.

Changes:

  • Replaced sid with ainsID in CSV export queries and variable names to match the database schema
  • Updated the ForceLeave function's SQL query to identify users' current room status based on their most recent log entry
  • Improved code readability by introducing a named constant for the enter/leave status and capitalizing SQL keywords

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

File Description
server/utils/csvexport.go Standardized identifier from sid to ainsID, added Enter constant for readability, capitalized SQL keywords, and improved variable naming consistency
server/db/user.go Refactored ForceLeave query to use a subquery approach for finding users' latest room status based on recent log entries

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +95 to +105
rows, err := tx.Query(`
SELECT ainsID
FROM log l
WHERE time = (
SELECT MAX(time)
FROM log
WHERE ainsID = l.ainsID
AND time >= ?
)
AND isEnter = 1
`, yesterdayStartTime)
Copy link

Copilot AI Feb 3, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The query logic may miss users who entered more than 24 hours ago and never left. The subquery SELECT MAX(time) FROM log WHERE ainsID = l.ainsID AND time >= ? only considers log entries from the last 24 hours. If a user entered 2+ days ago and has had no log activity since, they won't be selected for force-leave.

Consider removing the AND time >= ? condition from the subquery to check the user's latest log entry regardless of when it occurred. The outer condition isEnter = 1 will then correctly identify all users currently in the room based on their most recent log entry.

Copilot uses AI. Check for mistakes.
TimestampMillisecondDivisor = 1000
)

const Enter = 1
Copy link

Copilot AI Feb 3, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The constant Enter should follow Go naming conventions for exported identifiers. Since this constant represents the integer value for the "enter" state and is only used within this package, it should be unexported (lowercase). Consider renaming it to enterValue or enterStatus to better indicate what the constant represents and to make it package-private.

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants