removed locks, switching to WAL for SQLite default

This commit is contained in:
2021-10-25 02:12:12 +02:00
parent c30da099ed
commit efd0f9a6af
6 changed files with 46 additions and 143 deletions

View File

@@ -18,7 +18,6 @@ import (
"io/ioutil"
"math/rand"
"os"
"sync"
"time"
)
@@ -34,7 +33,6 @@ type DemoMatchLoaderConfig struct {
LoginKey string
ServerList string
Db *ent.Client
Lock *sync.RWMutex
Worker int
ApiKey string
RateLimit ratelimit.Limiter
@@ -51,7 +49,6 @@ type DemoMatchLoader struct {
loginKey string
serverList string
db *ent.Client
lock *sync.RWMutex
dp *DemoParser
parseDemo chan *Demo
parseMap map[string]bool
@@ -171,12 +168,11 @@ func (d *DemoMatchLoader) Setup(config *DemoMatchLoaderConfig) error {
d.loginKey = config.LoginKey
d.sentryFile = config.Sentry
d.serverList = config.ServerList
d.lock = config.Lock
d.db = config.Db
d.dp = &DemoParser{}
d.parseMap = map[string]bool{}
d.cache = config.Cache
err := d.dp.Setup(config.Db, config.Lock, config.Worker)
err := d.dp.Setup(config.Db, config.Worker)
if err != nil {
return err
}
@@ -357,9 +353,7 @@ func (d *DemoMatchLoader) gcWorker(apiKey string, rl ratelimit.Limiter) {
continue
}
d.lock.RLock()
iMatch, err := d.db.Match.Get(context.Background(), matchId)
d.lock.RUnlock()
if err != nil {
switch e := err.(type) {
case *ent.NotFoundError:
@@ -399,10 +393,7 @@ func (d *DemoMatchLoader) gcWorker(apiKey string, rl ratelimit.Limiter) {
var players []*ent.Player
for _, accountId := range lastRound.GetReservation().GetAccountIds() {
tPlayer, err := utils.GetPlayer(&utils.DBWithLock{
Client: d.db,
Lock: d.lock,
}, AccountId2SteamId(accountId), apiKey, rl)
tPlayer, err := utils.GetPlayer(d.db, AccountId2SteamId(accountId), apiKey, rl)
if err != nil {
log.Warningf("[DL] Unable to get player for steamid %d: %v", AccountId2SteamId(accountId), err)
continue
@@ -413,7 +404,6 @@ func (d *DemoMatchLoader) gcWorker(apiKey string, rl ratelimit.Limiter) {
demo.Url = lastRound.GetMap()
demo.MatchId = matchZero.GetMatchid()
d.lock.Lock()
tMatch, err := d.db.Match.Create().
SetID(matchZero.GetMatchid()).
AddPlayers(players...).
@@ -426,7 +416,6 @@ func (d *DemoMatchLoader) gcWorker(apiKey string, rl ratelimit.Limiter) {
SetScoreTeamB(int(lastRound.GetTeamScores()[1])).
SetMatchResult(int(lastRound.GetMatchResult())).
Save(context.Background())
d.lock.Unlock()
if err != nil {
log.Warningf("[DL] Unable to create match %d: %v", matchZero.GetMatchid(), err)
delete(d.parseMap, demo.ShareCode)
@@ -468,7 +457,6 @@ func (d *DemoMatchLoader) gcWorker(apiKey string, rl ratelimit.Limiter) {
}
kills, deaths, assists, hs, score, mvp := playerStatsFromRound(lastRound, mPlayer)
d.lock.Lock()
err := d.db.Stats.Create().
SetMatches(tMatch).
SetPlayers(mPlayer).
@@ -484,7 +472,6 @@ func (d *DemoMatchLoader) gcWorker(apiKey string, rl ratelimit.Limiter) {
SetMk4(mk4).
SetMk5(mk5).
Exec(context.Background())
d.lock.Unlock()
if err != nil {
log.Warningf("[DL] Unable to create stats for player %d in match %d: %v", mPlayer.ID, tMatch.ID, err)
}