fix: calendar day-of-week offset off by one, nav double-jump, race conditions
- Fix Jalali/Gregorian/Hijri day-of-week startOffset formulas (dow returns 0=Sat, not 0=Sun as the old comment claimed) - Fix calendar and export month picker navigation jumping 2 months (navMonth buttons already have pre-computed values; handlers were decrementing/incrementing them again) - Fix GetOrCreateUser/GetOrCreateDay race condition with INSERT OR IGNORE - Add month/day bounds validation in handleEditMsg to prevent panic
This commit is contained in:
@@ -289,15 +289,8 @@ func migrateSettings(db *sql.DB) {
|
||||
}
|
||||
|
||||
func (s *Store) GetOrCreateUser(chatID int64) (*User, error) {
|
||||
user, err := s.GetUserByChatID(chatID)
|
||||
if err == nil {
|
||||
return user, nil
|
||||
}
|
||||
if err != sql.ErrNoRows {
|
||||
return nil, err
|
||||
}
|
||||
_, err = s.db.Exec(
|
||||
"INSERT INTO users (chat_id) VALUES (?)",
|
||||
_, err := s.db.Exec(
|
||||
"INSERT OR IGNORE INTO users (chat_id) VALUES (?)",
|
||||
chatID,
|
||||
)
|
||||
if err != nil {
|
||||
@@ -399,15 +392,8 @@ func (s *Store) GetWorkType(id int64) (*WorkType, error) {
|
||||
}
|
||||
|
||||
func (s *Store) GetOrCreateDay(userID int64, date string) (*Day, error) {
|
||||
day, err := s.GetDay(userID, date)
|
||||
if err == nil {
|
||||
return day, nil
|
||||
}
|
||||
if err != sql.ErrNoRows {
|
||||
return nil, err
|
||||
}
|
||||
_, err = s.db.Exec(
|
||||
"INSERT INTO days (user_id, date) VALUES (?, ?)",
|
||||
_, err := s.db.Exec(
|
||||
"INSERT OR IGNORE INTO days (user_id, date) VALUES (?, ?)",
|
||||
userID, date,
|
||||
)
|
||||
if err != nil {
|
||||
|
||||
Reference in New Issue
Block a user