Add score to session save data
parent
5214c4aff4
commit
71889f7daa
@ -1,24 +1,26 @@
|
|||||||
package db
|
package db
|
||||||
|
|
||||||
func TryAddSeedCompletion(uuid []byte, seed string, mode int) (bool, error) {
|
func TryAddSeedCompletion(uuid []byte, seed string, mode int, score int) (bool, error) {
|
||||||
if len(seed) < 24 {
|
if len(seed) < 24 {
|
||||||
for range 24 - len(seed) {
|
for range 24 - len(seed) {
|
||||||
seed += "0"
|
seed += "0"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
newCompletion := true
|
||||||
|
|
||||||
var count int
|
var count int
|
||||||
err := handle.QueryRow("SELECT COUNT(*) FROM seedCompletions WHERE uuid = ? AND seed = ?", uuid, seed).Scan(&count)
|
err := handle.QueryRow("SELECT COUNT(*) FROM seedCompletions WHERE uuid = ? AND seed = ?", uuid, seed).Scan(&count)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return false, err
|
return false, err
|
||||||
} else if count > 0 {
|
} else if count > 0 {
|
||||||
return false, nil
|
newCompletion = false
|
||||||
}
|
}
|
||||||
|
|
||||||
_, err = handle.Exec("INSERT INTO seedCompletions (uuid, seed, mode, timestamp) VALUES (?, ?, ?, UTC_TIMESTAMP())", uuid, seed, mode)
|
_, err = handle.Exec("INSERT INTO seedCompletions (uuid, seed, mode, score, timestamp) VALUES (?, ?, ?, ?, UTC_TIMESTAMP()) ON DUPLICATE KEY UPDATE score = ?, timestamp = IF(score < ?, UTC_TIMESTAMP(), timestamp)", uuid, seed, mode, score, score, score)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return false, err
|
return false, err
|
||||||
}
|
}
|
||||||
|
|
||||||
return true, nil
|
return newCompletion, nil
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue