From 6a1d561e3af81aaa67dd834192697e39e3e4bc5d Mon Sep 17 00:00:00 2001 From: Jonathan Leech-Pepin Date: Tue, 18 Nov 2014 11:21:51 -0500 Subject: Fix logic for updating cache and setting variables. Turned (sx-network--ensure-user) into (sx-network--initialize) and added as hook for initialization. --- sx-networks.el | 32 +++++++++++++++++--------------- 1 file changed, 17 insertions(+), 15 deletions(-) (limited to 'sx-networks.el') diff --git a/sx-networks.el b/sx-networks.el index 315daba..fbb2d78 100644 --- a/sx-networks.el +++ b/sx-networks.el @@ -56,28 +56,30 @@ "Retrieve cached information for network user. If cache is not available, retrieve current data." - (or (and (sx-cache-get 'network-user) - (setq sx-network--user-sites + (or (and (setq sx-network--user-information (sx-cache-get 'network-user) + sx-network--user-sites (sx-network--map-site-url-to-site-api))) (sx-network--update))) (defun sx-network--update () - "Update user information." - (setq sx-network--user-information - (sx-method-call "me/associated" - '((types . (main_site meta_site))) - sx-network--user-filter - 'warn)) - (setq sx-network--user-sites (sx-network--map-site-url-to-site-api)) - (sx-cache-set 'network-user sx-network--user-information)) - -(defun sx-network--ensure-user () + "Update user information. + +Sets cache and then uses `sx-network--get-associated' to update +the variables." + (sx-cache-set 'network-user + (sx-method-call "me/associated" + '((types . (main_site meta_site))) + sx-network--user-filter + 'warn)) + (sx-network--get-associated)) + +(defun sx-network--initialize () "Ensure user-cache is available. -This should be called during initialization." +Added as hook to initialization." ;; Cache was not retrieved, retrieve it. - (unless sx-network--user-information - (sx-network--get-associated))) + (sx-network--get-associated)) +(add-hook 'sx-init--internal-hook #'sx-network--initialize) (defun sx-network--map-site-url-to-site-api () "Convert `me/associations' to a set of `api_site_parameter's. -- cgit v1.2.3 From cb4d53d57f5ee68aced5ff1a73829eea8a2d662b Mon Sep 17 00:00:00 2001 From: Jonathan Leech-Pepin Date: Tue, 18 Nov 2014 11:44:16 -0500 Subject: Correct naming of cache to correspond to sx-cache-get. --- sx-networks.el | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'sx-networks.el') diff --git a/sx-networks.el b/sx-networks.el index fbb2d78..755d62c 100644 --- a/sx-networks.el +++ b/sx-networks.el @@ -74,7 +74,7 @@ the variables." (sx-network--get-associated)) (defun sx-network--initialize () - "Ensure user-cache is available. + "Ensure network-user cache is available. Added as hook to initialization." ;; Cache was not retrieved, retrieve it. -- cgit v1.2.3