Commit 80c6b67e authored by Howl's avatar Howl
Browse files

Revert "Lock tables in cron"

This reverts commit d7fa7716.
parent d7fa7716
Loading
Loading
Loading
Loading
+1 −20
Changes for cron.go: 1 added line, 20 removed lines.
Original line number Diff line number Diff line
@@ -27,7 +27,6 @@ type config struct {
	CalculatePP             bool
	FixScoreDuplicates      bool `description:"might take a VERY long time"`

	Lock       bool `description:"Do this in prod if you have a lot of users. It will avoid memes of leaderboard update, but it will be slower (no multi mysql connections)"`
	LogQueries bool `description:"You don't wanna do this in prod."`
	Workers    int  `description:"The number of goroutines which should execute queries. Increasing it may make cron faster, depending on your system."`
}
@@ -79,9 +78,6 @@ func main() {
	defer db.Close()

	// spawn some workers
	if c.Lock {
		c.Workers = 1
	}
	fmt.Print("Spawning necessary workers...")
	for i := 0; i < c.Workers; i++ {
		chanWg.Add(1)
@@ -91,20 +87,6 @@ func main() {

	timeAtStart := time.Now()

	if c.Lock {
		locks := "LOCK TABLES "
		for _, i := range []string{"leaderboard_std", "leaderboard_ctb", "leaderboard_mania", "leaderboard_taiko", "users_stats", "scores", "users", "password_recovery"} {
			locks += i + " WRITE, "
		}
		locks = locks[:len(locks)-2]
		_, err = db.Exec(locks)
		if err != nil {
			queryError(err, locks)
			return
		}
		db.SetMaxOpenConns(1)
	}

	if c.CalculateAccuracy {
		fmt.Print("Starting accuracy calculator worker...")
		wg.Add(1)
@@ -151,7 +133,6 @@ func main() {
	color.Green("Data elaboration has been terminated.")
	color.Green("Execution time: %.4fs", time.Now().Sub(timeAtStart).Seconds())
	color.Yellow("Waiting for workers to finish...")
	op("UNLOCK TABLES")
	close(execOperations)
	chanWg.Wait()
}
@@ -167,7 +148,7 @@ func op(query string, params ...interface{}) {
}

// Operations that can be executed with a simple db.Exec, distributed across 8 workers.
var execOperations = make(chan operation, 100000)
var execOperations = make(chan operation, 10000)

func worker() {
	for op := range execOperations {