add cache

This commit is contained in:
Aine
2022-08-29 15:28:37 +03:00
parent 1a87929567
commit 5a5a649cba
4 changed files with 14 additions and 0 deletions

View File

@@ -81,6 +81,11 @@ func (b *Bot) migrateSettings(roomID id.RoomID) {
}
func (b *Bot) getSettings(roomID id.RoomID) (settings, error) {
cfg := b.cfg.Get(roomID.String())
if cfg != nil {
return cfg, nil
}
config := settings{}
err := b.lp.GetClient().GetRoomAccountData(roomID, settingskey, &config)
if err != nil {
@@ -90,11 +95,14 @@ func (b *Bot) getSettings(roomID id.RoomID) (settings, error) {
// In such cases, just return a default (empty) settings object.
err = nil
}
} else {
b.cfg.Set(roomID.String(), config)
}
return config, utils.UnwrapError(err)
}
func (b *Bot) setSettings(roomID id.RoomID, cfg settings) error {
b.cfg.Set(roomID.String(), cfg)
return utils.UnwrapError(b.lp.GetClient().SetRoomAccountData(roomID, settingskey, cfg))
}