refactor(settings): make calling settings_getSocialLinks only once

Fixes #8549

That status-go call was done A LOT because we try to access our own data often and we didn't use to cache it.
This commit is contained in:
Jonathan Rainville 2022-12-01 13:45:20 -05:00
parent d60a4b0c97
commit a94750fb2d
1 changed files with 13 additions and 0 deletions

View File

@ -39,6 +39,11 @@ QtObject:
type Service* = ref object of QObject type Service* = ref object of QObject
events: EventEmitter events: EventEmitter
settings: SettingsDto settings: SettingsDto
socialLinks: SocialLinks
# Forward declaration
proc fetchSocialLinks*(self: Service): SocialLinks
proc delete*(self: Service) = proc delete*(self: Service) =
self.QObject.delete self.QObject.delete
@ -52,6 +57,8 @@ QtObject:
try: try:
let response = status_settings.getSettings() let response = status_settings.getSettings()
self.settings = response.result.toSettingsDto() self.settings = response.result.toSettingsDto()
self.socialLinks = self.fetchSocialLinks()
except Exception as e: except Exception as e:
let errDesription = e.msg let errDesription = e.msg
error "error: ", errDesription error "error: ", errDesription
@ -819,7 +826,11 @@ QtObject:
except Exception as e: except Exception as e:
error "error setting bio", errDesription = e.msg error "error setting bio", errDesription = e.msg
proc getSocialLinks*(self: Service): SocialLinks = proc getSocialLinks*(self: Service): SocialLinks =
return self.socialLinks
proc fetchSocialLinks*(self: Service): SocialLinks =
try: try:
let response = status_settings.getSocialLinks() let response = status_settings.getSocialLinks()
@ -843,6 +854,8 @@ QtObject:
if(not response.error.isNil): if(not response.error.isNil):
error "error setting social links", errDescription = response.error.message error "error setting social links", errDescription = response.error.message
self.socialLinks = self.fetchSocialLinks()
result = true result = true
except Exception as e: except Exception as e:
error "error setting social links", errDesription = e.msg error "error setting social links", errDesription = e.msg