mirror of
https://github.com/Xevion/banner.git
synced 2025-12-10 12:06:34 -06:00
Fix nil key check, fix bad durations
This commit is contained in:
19
meta.go
19
meta.go
@@ -1,12 +1,17 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import log "github.com/rs/zerolog/log"
|
import (
|
||||||
|
"time"
|
||||||
|
|
||||||
|
"github.com/redis/go-redis/v9"
|
||||||
|
log "github.com/rs/zerolog/log"
|
||||||
|
)
|
||||||
|
|
||||||
// GetGuildName returns the name of the guild with the given ID, utilizing Redis to cache the value
|
// GetGuildName returns the name of the guild with the given ID, utilizing Redis to cache the value
|
||||||
func GetGuildName(guildID string) string {
|
func GetGuildName(guildID string) string {
|
||||||
// Check Redis for the guild name
|
// Check Redis for the guild name
|
||||||
guildName, err := kv.Get(ctx, "guild:"+guildID+":name").Result()
|
guildName, err := kv.Get(ctx, "guild:"+guildID+":name").Result()
|
||||||
if err != nil {
|
if err != nil && err != redis.Nil {
|
||||||
log.Error().Err(err).Msg("Error getting guild name from Redis")
|
log.Error().Err(err).Msg("Error getting guild name from Redis")
|
||||||
return "err"
|
return "err"
|
||||||
}
|
}
|
||||||
@@ -22,7 +27,7 @@ func GetGuildName(guildID string) string {
|
|||||||
log.Error().Err(err).Msg("Error getting guild name")
|
log.Error().Err(err).Msg("Error getting guild name")
|
||||||
|
|
||||||
// Store an invalid value in Redis so we don't keep trying to get the guild name
|
// Store an invalid value in Redis so we don't keep trying to get the guild name
|
||||||
_, err := kv.Set(ctx, "guild:"+guildID+":name", "x", 60*5).Result()
|
_, err := kv.Set(ctx, "guild:"+guildID+":name", "x", time.Minute*5).Result()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Error().Err(err).Msg("Error setting false guild name in Redis")
|
log.Error().Err(err).Msg("Error setting false guild name in Redis")
|
||||||
}
|
}
|
||||||
@@ -31,7 +36,7 @@ func GetGuildName(guildID string) string {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Cache the guild name in Redis
|
// Cache the guild name in Redis
|
||||||
kv.Set(ctx, "guild:"+guildID+":name", guild.Name, 60*60*3)
|
kv.Set(ctx, "guild:"+guildID+":name", guild.Name, time.Hour*3)
|
||||||
|
|
||||||
return guild.Name
|
return guild.Name
|
||||||
}
|
}
|
||||||
@@ -40,7 +45,7 @@ func GetGuildName(guildID string) string {
|
|||||||
func GetChannelName(channelID string) string {
|
func GetChannelName(channelID string) string {
|
||||||
// Check Redis for the channel name
|
// Check Redis for the channel name
|
||||||
channelName, err := kv.Get(ctx, "channel:"+channelID+":name").Result()
|
channelName, err := kv.Get(ctx, "channel:"+channelID+":name").Result()
|
||||||
if err != nil {
|
if err != nil && err != redis.Nil {
|
||||||
log.Error().Err(err).Msg("Error getting channel name from Redis")
|
log.Error().Err(err).Msg("Error getting channel name from Redis")
|
||||||
return "err"
|
return "err"
|
||||||
}
|
}
|
||||||
@@ -56,7 +61,7 @@ func GetChannelName(channelID string) string {
|
|||||||
log.Error().Err(err).Msg("Error getting channel name")
|
log.Error().Err(err).Msg("Error getting channel name")
|
||||||
|
|
||||||
// Store an invalid value in Redis so we don't keep trying to get the channel name
|
// Store an invalid value in Redis so we don't keep trying to get the channel name
|
||||||
_, err := kv.Set(ctx, "channel:"+channelID+":name", "x", 60*5).Result()
|
_, err := kv.Set(ctx, "channel:"+channelID+":name", "x", time.Minute*5).Result()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Error().Err(err).Msg("Error setting false channel name in Redis")
|
log.Error().Err(err).Msg("Error setting false channel name in Redis")
|
||||||
}
|
}
|
||||||
@@ -65,7 +70,7 @@ func GetChannelName(channelID string) string {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Cache the channel name in Redis
|
// Cache the channel name in Redis
|
||||||
kv.Set(ctx, "channel:"+channelID+":name", channel.Name, 60*60*3)
|
kv.Set(ctx, "channel:"+channelID+":name", channel.Name, time.Hour*3)
|
||||||
|
|
||||||
return channel.Name
|
return channel.Name
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user