Skip to content

Commit

Permalink
fix: fresh session first poll
Browse files Browse the repository at this point in the history
  • Loading branch information
williamsjokvist committed Feb 1, 2025
1 parent e296994 commit 76ccc33
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 23 deletions.
42 changes: 21 additions & 21 deletions cmd/tracking.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package cmd

import (
"context"
"errors"
"fmt"
"log"
"time"
Expand Down Expand Up @@ -76,34 +75,35 @@ func (ch *TrackingHandler) StartTracking(userCode string, restore bool) error {
}
session = sesh
} else {
user, err := ch.sqlDb.GetUserByCode(ctx, userCode)
if err != nil && !errors.Is(err, sql.ErrUserNotFound) {
return model.WrapError(model.ErrGetUser, err)
}

if user == nil {
user, err = ch.gameTracker.GetUser(ctx, userCode)
if err != nil {
return model.WrapError(model.ErrGetUser, err)
}
if err := ch.sqlDb.SaveUser(ctx, *user); err != nil {
return model.WrapError(model.ErrSaveUser, err)
}
}

session, err = ch.sqlDb.CreateSession(ctx, userCode)
sesh, err := ch.sqlDb.CreateSession(ctx, userCode)
if err != nil {
return model.WrapError(model.ErrCreateSession, err)
}
session.LP = user.LP
session.MR = user.MR
session.UserName = user.DisplayName
session = sesh
}

if session == nil {
return model.ErrCreateSession
}

user, err := ch.gameTracker.GetUser(ctx, userCode)
if err != nil {
return model.WrapError(model.ErrGetUser, err)
}
if err := ch.sqlDb.SaveUser(ctx, *user); err != nil {
return model.WrapError(model.ErrSaveUser, err)
}
session.LP = user.LP
session.MR = user.MR
session.UserName = user.DisplayName

ch.eventEmitter("match", model.Match{
UserName: session.UserName,
LP: session.LP,
MR: session.MR,
SessionId: session.Id,
UserId: session.UserId,
})

ticker := time.NewTicker(30 * time.Second)
ch.forcePollChan = make(chan struct{})
defer func() {
Expand Down
2 changes: 1 addition & 1 deletion pkg/model/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@ type RuntimeConfig struct {

type GUIConfig struct {
Locale string `ini:"locale" json:"locale" default:"en-GB"`
Theme ThemeName `ini:"theme" json:"theme" default:"default"`
Theme ThemeName `ini:"theme" json:"theme" default:"tekken"`
SideBar bool `ini:"sidebar" json:"sidebar" default:"true"`
}
2 changes: 1 addition & 1 deletion pkg/tracker/sf6/track.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ func (t *SF6Tracker) GetUser(ctx context.Context, userCode string) (*model.User,

func (t *SF6Tracker) Poll(ctx context.Context, cancel context.CancelFunc, session *model.Session, onNewMatch func(model.Match)) {
bl, err := t.cfnClient.GetBattleLog(ctx, session.UserId)
if err != nil {
if bl == nil || err != nil {

Check failure on line 40 in pkg/tracker/sf6/track.go

View workflow job for this annotation

GitHub Actions / go-lint

SA5011(related information): this check suggests that the pointer can be nil (staticcheck)
cancel()
}
if len(bl.ReplayList) == 0 {

Check failure on line 43 in pkg/tracker/sf6/track.go

View workflow job for this annotation

GitHub Actions / go-lint

SA5011: possible nil pointer dereference (staticcheck)
Expand Down

0 comments on commit 76ccc33

Please sign in to comment.