Skip to content

Commit

Permalink
feature: Log time used to fetch GuildSettings. (#9)
Browse files Browse the repository at this point in the history
  • Loading branch information
myrkvi authored Aug 20, 2024
2 parents 493dfbf + 66f4a59 commit fc97061
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions model/guild_settings.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package model

import (
"log/slog"
"time"

"github.com/disgoorg/snowflake/v2"
Expand Down Expand Up @@ -33,11 +34,18 @@ type GuildSettings struct {
}

func GetGuildSettings(guildID snowflake.ID) (*GuildSettings, error) {
cur := time.Now()
settings := GuildSettings{GuildID: guildID}
res := DB.FirstOrCreate(&settings, "guild_id = ?", guildID)
if res.Error != nil {
return nil, res.Error
}
dur := time.Since(cur)
if dur > time.Second {
slog.Warn("GetGuildSettings took too long", "guild_id", guildID, "dur", dur)
} else {
slog.Debug("GetGuildSettings", "guild_id", guildID, "dur", dur)
}
return &settings, nil
}

Expand Down

0 comments on commit fc97061

Please sign in to comment.