only cache get_setting value when it's not the default value
This commit is contained in:
parent
203216d94d
commit
473c2723e7
1 changed files with 7 additions and 4 deletions
|
@ -147,6 +147,7 @@ class Channel(IRCObject.Object):
|
||||||
|
|
||||||
def set_setting(self, setting: str, value: typing.Any):
|
def set_setting(self, setting: str, value: typing.Any):
|
||||||
self.bot.database.channel_settings.set(self.id, setting, value)
|
self.bot.database.channel_settings.set(self.id, setting, value)
|
||||||
|
cache_key = self._setting_cache_key(setting)
|
||||||
self._cache_setting(self._setting_cache_key(setting), value)
|
self._cache_setting(self._setting_cache_key(setting), value)
|
||||||
def get_setting(self, setting: str, default: typing.Any=None
|
def get_setting(self, setting: str, default: typing.Any=None
|
||||||
) -> typing.Any:
|
) -> typing.Any:
|
||||||
|
@ -154,10 +155,12 @@ class Channel(IRCObject.Object):
|
||||||
if self.bot.cache.has_item(cache_key):
|
if self.bot.cache.has_item(cache_key):
|
||||||
return self.bot.cache.get(cache_key)
|
return self.bot.cache.get(cache_key)
|
||||||
|
|
||||||
value = self.bot.database.channel_settings.get(self.id, setting,
|
value = self.bot.database.channel_settings.get(self.id, setting, None)
|
||||||
default)
|
if value == None:
|
||||||
self._cache_setting(cache_key, value)
|
return default
|
||||||
return value
|
else:
|
||||||
|
self._cache_setting(cache_key, value)
|
||||||
|
return value
|
||||||
|
|
||||||
def find_settings(self, pattern: str, default: typing.Any=[]
|
def find_settings(self, pattern: str, default: typing.Any=[]
|
||||||
) -> typing.List[typing.Any]:
|
) -> typing.List[typing.Any]:
|
||||||
|
|
Loading…
Reference in a new issue