From e6139c9f4950173e416b6bfabaceb2e1e813cedf Mon Sep 17 00:00:00 2001 From: zotlabs Date: Thu, 6 Apr 2017 16:24:19 -0700 Subject: revisit the import_author_zot algorithm yet again. There was one bug that we weren't returning necessary information in the first SQL query - and performance/loading problem if one tries to refresh a dead site. --- include/zot.php | 36 ++++++++++++++++++++++++++++++++++-- 1 file changed, 34 insertions(+), 2 deletions(-) (limited to 'include') diff --git a/include/zot.php b/include/zot.php index 8afed1c3c..d1fd1db6a 100644 --- a/include/zot.php +++ b/include/zot.php @@ -3585,7 +3585,9 @@ function import_author_zot($x) { // of a hassle to repair. If either or both are missing, do a full discovery probe. $hash = make_xchan_hash($x['guid'],$x['guid_sig']); - $r1 = q("select hubloc_url from hubloc where hubloc_guid = '%s' and hubloc_guid_sig = '%s' and hubloc_primary = 1 limit 1", + + $r1 = q("select hubloc_url, hubloc_updated, site_dead from hubloc left join site on + hubloc_url = site_url where hubloc_guid = '%s' and hubloc_guid_sig = '%s' and hubloc_primary = 1 limit 1", dbesc($x['guid']), dbesc($x['guid_sig']) ); @@ -3595,12 +3597,42 @@ function import_author_zot($x) { dbesc($x['guid_sig']) ); + $site_dead = false; + + if($r1 && intval($r1[0]['site_dead'])) { + $site_dead = true; + } + + // We have valid and somewhat fresh information. + if($r1 && $r2 && $r1[0]['hubloc_updated'] > datetime_convert('UTC','UTC','now - 1 week')) { logger('in cache', LOGGER_DEBUG); return $hash; } - logger('not in cache - probing: ' . print_r($x,true), LOGGER_DEBUG); + logger('not in cache or cache stale - probing: ' . print_r($x,true), LOGGER_DEBUG,LOG_INFO); + + // The primary hub may be dead. Try to find another one associated with this identity that is + // still alive. If we find one, use that url for the discovery/refresh probe. Otherwise, the dead site + // is all we have and there is no point probing it. Just return the hash indicating we have a + // cached entry and the identity is valid. It's just unreachable until they bring back their + // server from the grave or create another clone elsewhere. + + if($site_dead) { + logger('dead site - ignoring', LOGGER_DEBUG,LOG_INFO); + + $r = q("select hubloc_url from hubloc left join site on hubloc_url = site_url + where hubloc_hash = '%s' and site_dead = 0", + dbesc($hash) + ); + if($r) { + logger('found another site that is not dead: ' . $r[0]['hubloc_url'], LOGGER_DEBUG,LOG_INFO); + $x['url'] = $r[0]['hubloc_url']; + } + else { + return $hash; + } + } $them = array('hubloc_url' => $x['url'], 'xchan_guid' => $x['guid'], 'xchan_guid_sig' => $x['guid_sig']); if(zot_refresh($them)) -- cgit v1.2.3 From e685c580f27c438fcda2b37005fdb0a10162b42c Mon Sep 17 00:00:00 2001 From: zotlabs Date: Thu, 6 Apr 2017 19:55:43 -0700 Subject: only log zot_refresh content if json decode was successful. --- include/zot.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'include') diff --git a/include/zot.php b/include/zot.php index d1fd1db6a..3e1b27c83 100644 --- a/include/zot.php +++ b/include/zot.php @@ -310,8 +310,6 @@ function zot_refresh($them, $channel = null, $force = false) { $result = z_post_url($url . $rhs,$postvars); - logger('zot_refresh: zot-info: ' . print_r($result,true), LOGGER_DATA, LOG_DEBUG); - if ($result['success']) { $j = json_decode($result['body'],true); @@ -321,6 +319,8 @@ function zot_refresh($them, $channel = null, $force = false) { return false; } + logger('zot-info: ' . print_r($result,true), LOGGER_DATA, LOG_DEBUG); + $signed_token = ((is_array($j) && array_key_exists('signed_token',$j)) ? $j['signed_token'] : null); if($signed_token) { $valid = rsa_verify('token.' . $token,base64url_decode($signed_token),$j['key']); -- cgit v1.2.3 From 28207c33132ac4fb8cd3792df52d776c80d054d9 Mon Sep 17 00:00:00 2001 From: Mario Vavti Date: Fri, 7 Apr 2017 11:31:10 +0200 Subject: css fixes and missing string --- include/photos.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'include') diff --git a/include/photos.php b/include/photos.php index a3869a72e..2d4907b33 100644 --- a/include/photos.php +++ b/include/photos.php @@ -529,7 +529,8 @@ function photos_album_widget($channelx,$observer,$sortkey = 'display_path',$dire '$albums' => $albums['albums'], '$baseurl' => z_root(), '$upload' => ((perm_is_allowed($channelx['channel_id'],(($observer) ? $observer['xchan_hash'] : ''),'write_storage')) - ? t('Upload New Photos') : '') + ? t('Upload New Photos') : ''), + '$recent_photos' => t('Recent Photos') )); } -- cgit v1.2.3 From 113bfe8fa256c7e8145a84fa43ab4549384b025d Mon Sep 17 00:00:00 2001 From: Mario Vavti Date: Fri, 7 Apr 2017 18:41:13 +0200 Subject: remove redundant string --- include/photos.php | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'include') diff --git a/include/photos.php b/include/photos.php index 2d4907b33..a3869a72e 100644 --- a/include/photos.php +++ b/include/photos.php @@ -529,8 +529,7 @@ function photos_album_widget($channelx,$observer,$sortkey = 'display_path',$dire '$albums' => $albums['albums'], '$baseurl' => z_root(), '$upload' => ((perm_is_allowed($channelx['channel_id'],(($observer) ? $observer['xchan_hash'] : ''),'write_storage')) - ? t('Upload New Photos') : ''), - '$recent_photos' => t('Recent Photos') + ? t('Upload New Photos') : '') )); } -- cgit v1.2.3