From 3cf3f7437ea4c25c7a7fdcf04bfcf72be2d32698 Mon Sep 17 00:00:00 2001 From: friendica Date: Mon, 28 Jan 2013 20:51:37 -0800 Subject: It's really not supposed to be quite this chatty on the network - ah that's why. Oops. --- include/items.php | 24 ++++++++++++++++++------ include/zot.php | 5 +++++ 2 files changed, 23 insertions(+), 6 deletions(-) diff --git a/include/items.php b/include/items.php index 3e296177a..92e256ea9 100755 --- a/include/items.php +++ b/include/items.php @@ -515,10 +515,15 @@ function get_item_elements($x) { else return array(); - if(import_author_xchan($x['owner'])) - $arr['owner_xchan'] = base64url_encode(hash('whirlpool',$x['owner']['guid'] . $x['owner']['guid_sig'], true)); - else - return array(); + // save a potentially expensive lookup if author == owner + if($arr['author_xchan'] === base64url_encode(hash('whirlpool',$x['owner']['guid'] . $x['owner']['guid_sig'], true))) + $arr['owner_xchan'] = $arr['author_xchan']; + else { + if(import_author_xchan($x['owner'])) + $arr['owner_xchan'] = base64url_encode(hash('whirlpool',$x['owner']['guid'] . $x['owner']['guid_sig'], true)); + else + return array(); + } return $arr; @@ -527,13 +532,20 @@ function get_item_elements($x) { function import_author_xchan($x) { + $r = q("select hubloc_url from hubloc where hubloc_guid = '%s' and hubloc_guid_sig = '%s' and (hubloc_flags & %d) limit 1", dbesc($x['guid']), dbesc($x['guid_sig']), - intval(HUBLOG_FLAGS_PRIMARY) + intval(HUBLOC_FLAGS_PRIMARY) ); - if($r) + + if($r) { + logger('import_author_xchan: in cache', LOGGER_DEBUG); return true; + } + + logger('import_author_xchan: entry not in cache - probing: ' . print_r($x,true), LOGGER_DEBUG); + $them = array('hubloc_url' => $x['url'],'xchan_guid' => $x['guid'], 'xchan_guid_sig' => $x['guid_sig']); return zot_refresh($them); } diff --git a/include/zot.php b/include/zot.php index 8e3f0303e..a1169ea3b 100644 --- a/include/zot.php +++ b/include/zot.php @@ -730,6 +730,11 @@ function zot_import($arr) { $data = json_decode($arr['body'],true); + if(! $data) { + logger('zot_import: empty body'); + return array(); + } + // logger('zot_import: data1: ' . print_r($data,true)); if(array_key_exists('iv',$data)) { -- cgit v1.2.3