perf(db): remove useless XP data

This commit is contained in:
Anhgelus Morhtuuzh 2025-05-13 17:35:03 +02:00
parent 067e149e72
commit eaf9fa51cd
Signed by: anhgelus
GPG key ID: CAD341EFA92DDDE5
3 changed files with 34 additions and 70 deletions

View file

@ -1,7 +1,6 @@
package user
import (
"fmt"
"github.com/anhgelus/gokord"
"github.com/anhgelus/gokord/utils"
"github.com/anhgelus/les-copaings-bot/config"
@ -9,7 +8,6 @@ import (
"github.com/bwmarrin/discordgo"
"slices"
"sync"
"time"
)
type cXP struct {
@ -61,16 +59,14 @@ func (c *Copaing) GetXP() (uint, error) {
func (c *Copaing) GetXPForDays(n uint) (uint, error) {
xp := uint(0)
var y, d int
var m time.Month
if gokord.Debug {
y, m, d = time.Unix(time.Now().Unix()-int64(24*60*60), 0).Date() // reduce time for debug
} else {
y, m, d = time.Unix(time.Now().Unix()-int64(n*24*60*60), 0).Date()
}
rows, err := gokord.DB.
Model(&CopaingXP{}).
Where(fmt.Sprintf("created_at >= '%d-%d-%d' and guild_id = ? and copaing_id = ?", y, m, d), c.GuildID, c.ID).
Where(
"created_at >= '?' and guild_id = ? and copaing_id = ?",
exp.TimeStampNDaysBefore(n),
c.GuildID,
c.ID,
).
Rows()
defer rows.Close()
if err != nil {