From 765d6e0a97f135755d6ec1322f6e3272bc0ae620 Mon Sep 17 00:00:00 2001 From: friendica Date: Fri, 14 Jun 2013 16:54:58 -0700 Subject: push refresh messages, performance work on conversations and configs, doc updates --- include/config.php | 34 +++++++++++++++++++------- include/conversation.php | 7 ++++-- include/deliver.php | 13 ++++++---- include/directory.php | 7 +++++- include/notifier.php | 63 +++++++++++++++++++++++++++++++++++++++--------- 5 files changed, 95 insertions(+), 29 deletions(-) (limited to 'include') diff --git a/include/config.php b/include/config.php index 5db0a3d05..92fae165b 100644 --- a/include/config.php +++ b/include/config.php @@ -129,19 +129,35 @@ function del_config($family,$key) { function load_pconfig($uid,$family) { global $a; - $r = q("SELECT * FROM `pconfig` WHERE `cat` = '%s' AND `uid` = %d", - dbesc($family), - intval($uid) - ); - if(count($r)) { + + if(! array_key_exists($uid,$a->config)) + $a->config[$uid] = array(); + + if($family) { + $r = q("SELECT * FROM `pconfig` WHERE `cat` = '%s' AND `uid` = %d", + dbesc($family), + intval($uid) + ); + } + else { + $r = q("SELECT * FROM `pconfig` WHERE `uid` = %d", + intval($uid) + ); + } + + if($r) { foreach($r as $rr) { $k = $rr['k']; - $a->config[$uid][$family][$k] = $rr['v']; + $c = $rr['cat']; + if(! array_key_exists($c,$a->config[$uid])) + $a->config[$uid][$c] = array(); + $a->config[$uid][$c][$k] = $rr['v']; } - } else if ($family != 'config') { + } +// else if ($family != 'config') { // Negative caching - $a->config[$uid][$family] = "!!"; - } +// $a->config[$uid][$family] = "!!"; +// } } diff --git a/include/conversation.php b/include/conversation.php index 13f67c4dd..8e69e9ea3 100644 --- a/include/conversation.php +++ b/include/conversation.php @@ -365,7 +365,7 @@ function visible_activity($item) { * */ -if(!function_exists('conversation')) { + function conversation(&$a, $items, $mode, $update, $page_mode = 'traditional') { $tstart = dba_timer(); @@ -374,6 +374,8 @@ function conversation(&$a, $items, $mode, $update, $page_mode = 'traditional') { $ssl_state = ((local_user()) ? true : false); + if(local_user()) + load_pconfig(local_user(),''); $arr_blocked = null; @@ -678,6 +680,7 @@ function conversation(&$a, $items, $mode, $update, $page_mode = 'traditional') { } else { + // Normal View // logger('conv: items: ' . print_r($items,true)); @@ -790,7 +793,7 @@ function conversation(&$a, $items, $mode, $update, $page_mode = 'traditional') { return $o; -}} +} function best_link_url($item) { diff --git a/include/deliver.php b/include/deliver.php index c5ed35c87..547d009cc 100644 --- a/include/deliver.php +++ b/include/deliver.php @@ -23,11 +23,14 @@ function deliver_run($argv, $argc) { if($r[0]['outq_posturl'] === z_root() . '/post') { // local delivery // we should probably batch these and save a few delivery processes - $msg = array('body' => json_encode(array('pickup' => array(array('notify' => json_decode($r[0]['outq_notify'],true),'message' => json_decode($r[0]['outq_msg'],true)))))); - zot_import($msg); - $r = q("delete from outq where outq_hash = '%s' limit 1", - dbesc($argv[$x]) - ); + // If there is no outq_msg, this is a refresh_all message which does not require local handling + if($r[0]['outq_msg']) { + $msg = array('body' => json_encode(array('pickup' => array(array('notify' => json_decode($r[0]['outq_notify'],true),'message' => json_decode($r[0]['outq_msg'],true)))))); + zot_import($msg); + $r = q("delete from outq where outq_hash = '%s' limit 1", + dbesc($argv[$x]) + ); + } } else { $result = zot_zot($r[0]['outq_posturl'],$r[0]['outq_notify']); diff --git a/include/directory.php b/include/directory.php index 5f24b4af8..5f3696a58 100644 --- a/include/directory.php +++ b/include/directory.php @@ -41,11 +41,16 @@ function directory_run($argv, $argc){ $url = DIRECTORY_FALLBACK_MASTER . '/post'; } + // ensure the upstream directory is updated + $packet = zot_build_packet($channel,'refresh'); $z = zot_zot($url,$packet); - // re-queue if unsuccessful + // Now update all the connections + + proc_run('php','notifier','refresh_all',$channel['channel_id']); + } if (array_search(__file__,get_included_files())===0){ diff --git a/include/notifier.php b/include/notifier.php index 159931124..d72fa29b5 100644 --- a/include/notifier.php +++ b/include/notifier.php @@ -53,6 +53,7 @@ require_once('include/html2plain.php'); * * ZOT * permission_update abook_id + * refresh_all channel_id * relay item_id (item was relayed to owner, we will deliver it as owner) * */ @@ -136,6 +137,7 @@ function notifier_run($argv, $argc){ $recipients = array(); $url_recipients = array(); $normal_mode = true; + $packet_type = 'undefined'; if($cmd === 'mail') { $normal_mode = false; @@ -186,6 +188,27 @@ function notifier_run($argv, $argc){ $recipients[] = $suggest[0]['cid']; $item = $suggest[0]; } + elseif($cmd === 'refresh_all') { + $s = q("select * from channel where channel_id = %d limit 1", + intval($item_id) + ); + if($s) + $channel = $s[0]; + $uid = $item_id; + $recipients = array(); + $r = q("select * from abook where abook_channel = %d and not (abook_flags & %d) and not (abook_flags & %d)", + intval($item_id), + intval(ABOOK_FLAG_SELF), + intval(ABOOK_FLAG_PENDING) + ); + if($r) { + foreach($r as $rr) { + $recipients[] = $rr['abook_xchan']; + } + } + $private = false; + $packet_type = 'refresh'; + } else { // Normal items @@ -346,18 +369,34 @@ function notifier_run($argv, $argc){ foreach($hubs as $hub) { $hash = random_string(); - $n = zot_build_packet($channel,'notify',$env_recips,(($private) ? $hub['hubloc_sitekey'] : null),$hash); - q("insert into outq ( outq_hash, outq_account, outq_channel, outq_posturl, outq_async, outq_created, outq_updated, outq_notify, outq_msg ) values ( '%s', %d, %d, '%s', %d, '%s', '%s', '%s', '%s' )", - dbesc($hash), - intval($target_item['aid']), - intval($target_item['uid']), - dbesc($hub['hubloc_callback']), - intval(1), - dbesc(datetime_convert()), - dbesc(datetime_convert()), - dbesc($n), - dbesc(json_encode($encoded_item)) - ); + if($packet_type === 'refresh') { + $n = zot_build_packet($channel,'refresh'); + q("insert into outq ( outq_hash, outq_account, outq_channel, outq_posturl, outq_async, outq_created, outq_updated, outq_notify, outq_msg ) values ( '%s', %d, %d, '%s', %d, '%s', '%s', '%s', '%s' )", + dbesc($hash), + intval($channel['channel_account']), + intval($channel['channel_id']), + dbesc($hub['hubloc_callback']), + intval(1), + dbesc(datetime_convert()), + dbesc(datetime_convert()), + dbesc($n), + dbesc('') + ); + } + else { + $n = zot_build_packet($channel,'notify',$env_recips,(($private) ? $hub['hubloc_sitekey'] : null),$hash); + q("insert into outq ( outq_hash, outq_account, outq_channel, outq_posturl, outq_async, outq_created, outq_updated, outq_notify, outq_msg ) values ( '%s', %d, %d, '%s', %d, '%s', '%s', '%s', '%s' )", + dbesc($hash), + intval($target_item['aid']), + intval($target_item['uid']), + dbesc($hub['hubloc_callback']), + intval(1), + dbesc(datetime_convert()), + dbesc(datetime_convert()), + dbesc($n), + dbesc(json_encode($encoded_item)) + ); + } $deliver[] = $hash; if(count($deliver) >= $deliveries_per_process) { -- cgit v1.2.3