forked from botlabs-gg/yagpdb
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
web: move and simplify guild caching
- Loading branch information
1 parent
13b3088
commit d70786e
Showing
5 changed files
with
120 additions
and
77 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
package discorddata | ||
|
||
import ( | ||
"github.com/jonas747/yagpdb/bot" | ||
"github.com/jonas747/yagpdb/bot/eventsystem" | ||
"github.com/jonas747/yagpdb/common/pubsub" | ||
) | ||
|
||
type EvictData struct { | ||
Keys []string `json:"keys"` | ||
} | ||
|
||
func init() { | ||
pubsub.AddHandler("web_discorddata_evict", func(event *pubsub.Event) { | ||
data := event.Data.(*EvictData) | ||
|
||
for _, v := range data.Keys { | ||
applicationCache.Delete(v) | ||
} | ||
}, EvictData{}) | ||
} | ||
|
||
var _ bot.BotInitHandler = (*Plugin)(nil) | ||
|
||
func (p *Plugin) BotInit() { | ||
eventsystem.AddHandlerAsyncLast(p, p.handleInvalidateGuildCache, eventsystem.EventGuildRoleCreate, | ||
eventsystem.EventGuildRoleUpdate, | ||
eventsystem.EventGuildRoleDelete, | ||
eventsystem.EventChannelCreate, | ||
eventsystem.EventChannelUpdate, | ||
eventsystem.EventChannelDelete) | ||
} | ||
|
||
func (p *Plugin) handleInvalidateGuildCache(evt *eventsystem.EventData) (retry bool, err error) { | ||
PubEvictGuild(evt.GS.ID) | ||
return false, nil | ||
} | ||
|
||
func pubEvictCache(keys ...string) { | ||
pubsub.Publish("web_discorddata_evict", -1, EvictData{ | ||
Keys: keys, | ||
}) | ||
} | ||
|
||
func PubEvictGuild(guildID int64) { | ||
pubEvictCache(keyFullGuild(guildID)) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters