Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions internal/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ type Platform struct {
AdminToken string
SessionSigningToken string
DiscordWebhook *DiscordWebhook
Caching bool
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Might be worth giving this a more descriptive name like EnableMembershipListCaching or something

}

type DiscordWebhook struct {
Expand Down Expand Up @@ -84,6 +85,7 @@ func Get() *Config {
URL: cl.Get("platform.discordWebhook.url").AsString(),
ThreadID: cl.Get("platform.discordWebhook.threadID").AsString(),
},
Caching: cl.WithDefault("platform.caching", true).AsBool(),
},
}

Expand Down
20 changes: 20 additions & 0 deletions internal/guildScraper/checkMember.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ import (
"log/slog"
"sync"
"time"

"github.com/CSSUoB/society-voting/internal/config"
)

var (
Expand All @@ -16,6 +18,24 @@ var (
)

func GetMember(studentID string) (*GuildMember, error) {
conf := config.Get().Platform

if !conf.Caching {
members, err := GetMembersList()

if err != nil {
slog.Warn("failed to pull membership list", "error", err)
Comment thread
MattyTheHacker marked this conversation as resolved.
return nil, fmt.Errorf("pull membership list: %w", err)
}

for _, x := range members {
if x.ID == studentID {
return x, nil
}
}
Comment thread
MattyTheHacker marked this conversation as resolved.
return nil, nil
}

cachedMembershipListLock.RLock()

if time.Since(cachedMembershipListLastRefreshed) > time.Minute*5 {
Expand Down