-
Notifications
You must be signed in to change notification settings - Fork 2
fix: 月次ログが送信されない問題を修正 #217
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -16,9 +16,11 @@ const ( | |
| TimestampMillisecondDivisor = 1000 | ||
| ) | ||
|
|
||
| const Enter = 1 | ||
|
||
|
|
||
| // csvExport exports log data as CSV text | ||
| func csvExport(d *sql.DB) (string, error) { | ||
| rows, err := d.Query(`select time,log.sid,name,log.isenter,ext from log,users where log.sid=users.sid`) | ||
| rows, err := d.Query(`SELECT log.time,log.ainsID,users.name,log.isenter,log.ext FROM log,users WHERE log.ainsID=users.ainsID`) | ||
| if err != nil { | ||
| return "", err | ||
| } | ||
|
|
@@ -27,18 +29,18 @@ func csvExport(d *sql.DB) (string, error) { | |
| for rows.Next() { | ||
| var ( | ||
| ts int64 | ||
| sid string | ||
| ainsID string | ||
| name string | ||
| isenter int64 | ||
| isEnter int64 | ||
| ext string | ||
| ) | ||
| if err := rows.Scan(&ts, &sid, &name, &isenter, &ext); err != nil { | ||
| if err := rows.Scan(&ts, &ainsID, &name, &isEnter, &ext); err != nil { | ||
| return "", err | ||
| } | ||
|
|
||
| datefmted := time.Unix(ts/TimestampMillisecondDivisor, 0).Format("2006-01-02 15:04:05") | ||
| entstr := "Leave" | ||
| if isenter == 1 { | ||
| if isEnter == Enter { | ||
| entstr = "Enter" | ||
| } | ||
|
|
||
|
|
@@ -61,9 +63,9 @@ func csvExport(d *sql.DB) (string, error) { | |
| } | ||
| mess = strings.Replace(mess, "\"", "\"\"", -1) | ||
|
|
||
| csv += fmt.Sprintf("%v,%v,%v,%v,%v,\"%v\"\n", datefmted, sid, name, entstr, useage, mess) | ||
| csv += fmt.Sprintf("%v,%v,%v,%v,%v,\"%v\"\n", datefmted, ainsID, name, entstr, useage, mess) | ||
| } else { | ||
| csv += fmt.Sprintf("%v,%v,%v,%v,,\n", datefmted, sid, name, entstr) | ||
| csv += fmt.Sprintf("%v,%v,%v,%v,,\n", datefmted, ainsID, name, entstr) | ||
| } | ||
| } | ||
| err = rows.Close() | ||
|
|
@@ -101,7 +103,7 @@ func sendMonthlyLog(d *sql.DB) error { | |
| return err | ||
| } | ||
|
|
||
| if _, err = d.Exec(`delete from log`); err != nil { | ||
| if _, err = d.Exec(`DELETE FROM log`); err != nil { | ||
| return err | ||
| } | ||
| return nil | ||
|
|
||
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 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 conditionisEnter = 1will then correctly identify all users currently in the room based on their most recent log entry.