From 1434130264836916001fe191dd237e51af5c6e3e Mon Sep 17 00:00:00 2001 From: friendica Date: Tue, 24 Feb 2015 20:21:21 -0800 Subject: don't send deleted items upstream - only downstream. --- include/notifier.php | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) (limited to 'include/notifier.php') diff --git a/include/notifier.php b/include/notifier.php index fe6ac33c0..c77857087 100644 --- a/include/notifier.php +++ b/include/notifier.php @@ -315,9 +315,12 @@ function notifier_run($argv, $argc){ $r = fetch_post_tags($r); $target_item = $r[0]; + $deleted_item = false; - if($target_item['item_restrict'] & ITEM_DELETED) + if($target_item['item_restrict'] & ITEM_DELETED) { logger('notifier: target item ITEM_DELETED', LOGGER_DEBUG); + $deleted_item = true; + } $unforwardable = ITEM_UNPUBLISHED|ITEM_DELAYED_PUBLISH|ITEM_WEBPAGE|ITEM_BUILDBLOCK|ITEM_PDL; if($target_item['item_restrict'] & $unforwardable) { @@ -376,7 +379,7 @@ function notifier_run($argv, $argc){ // tag_deliver'd post which needs to be sent back to the original author - if(($cmd === 'uplink') && ($parent_item['item_flags'] & ITEM_UPLINK) && (! $top_level_post)) { + if(($cmd === 'uplink') && ($parent_item['item_flags'] & ITEM_UPLINK) && (! $top_level_post) && (! $deleted_item)) { logger('notifier: uplink'); $uplink = true; } @@ -397,7 +400,7 @@ function notifier_run($argv, $argc){ // if our parent is a tag_delivery recipient, uplink to the original author causing // a delivery fork. - if(($parent_item['item_flags'] & ITEM_UPLINK) && (! $top_level_post) && ($cmd !== 'uplink')) { + if(($parent_item['item_flags'] & ITEM_UPLINK) && (! $top_level_post) && ($cmd !== 'uplink') && (! $deleted_item)) { logger('notifier: uplinking this item'); proc_run('php','include/notifier.php','uplink',$item_id); } -- cgit v1.2.3 From b32841e2ddc53758957ca3afccb3e045fdf2e9fe Mon Sep 17 00:00:00 2001 From: friendica Date: Wed, 25 Feb 2015 15:27:33 -0800 Subject: Found the cause of the delete looping, and I can prevent it going forward. The issue remains what to do about comments which are already in the DB and have ITEM_ORIGIN incorrectly set. We can't exactly reset them because the "original" context has been lost. (Sorry but couldn't resist an insider pun that none of you will be able to follow anyway). Read the comments. --- include/notifier.php | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) (limited to 'include/notifier.php') diff --git a/include/notifier.php b/include/notifier.php index c77857087..f64732884 100644 --- a/include/notifier.php +++ b/include/notifier.php @@ -366,6 +366,11 @@ function notifier_run($argv, $argc){ $encoded_item = encode_item($target_item); + // Send comments to the owner to re-deliver to everybody in the conversation + // We only do this if the item in question originated on this site. This prevents looping. + // To clarify, a site accepting a new comment is responsible for sending it to the owner for relay. + // Relaying should never be initiated on a post that arrived from elsewhere. + $relay_to_owner = (((! $top_level_post) && ($target_item['item_flags'] & ITEM_ORIGIN)) ? true : false); $uplink = false; @@ -379,7 +384,7 @@ function notifier_run($argv, $argc){ // tag_deliver'd post which needs to be sent back to the original author - if(($cmd === 'uplink') && ($parent_item['item_flags'] & ITEM_UPLINK) && (! $top_level_post) && (! $deleted_item)) { + if(($cmd === 'uplink') && ($parent_item['item_flags'] & ITEM_UPLINK) && (! $top_level_post)) { logger('notifier: uplink'); $uplink = true; } @@ -400,7 +405,7 @@ function notifier_run($argv, $argc){ // if our parent is a tag_delivery recipient, uplink to the original author causing // a delivery fork. - if(($parent_item['item_flags'] & ITEM_UPLINK) && (! $top_level_post) && ($cmd !== 'uplink') && (! $deleted_item)) { + if(($parent_item['item_flags'] & ITEM_UPLINK) && (! $top_level_post) && ($cmd !== 'uplink')) { logger('notifier: uplinking this item'); proc_run('php','include/notifier.php','uplink',$item_id); } -- cgit v1.2.3 From b9e485be54317b68c994c5ffa3b2ffe21f767775 Mon Sep 17 00:00:00 2001 From: friendica Date: Wed, 25 Feb 2015 16:51:39 -0800 Subject: this may actually fix the deliver loop when deleting existing items. It's hackish but I don't see any other way out. --- include/notifier.php | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) (limited to 'include/notifier.php') diff --git a/include/notifier.php b/include/notifier.php index f64732884..22adc78a3 100644 --- a/include/notifier.php +++ b/include/notifier.php @@ -371,7 +371,14 @@ function notifier_run($argv, $argc){ // To clarify, a site accepting a new comment is responsible for sending it to the owner for relay. // Relaying should never be initiated on a post that arrived from elsewhere. - $relay_to_owner = (((! $top_level_post) && ($target_item['item_flags'] & ITEM_ORIGIN)) ? true : false); + // We should normally be able to rely on ITEM_ORIGIN, but start_delivery_chain() incorrectly set this + // flag on comments for an extended period. So we'll also call comment_local_origin() which looks at + // the hostname in the message_id and provides a second (fallback) opinion. + + $relay_to_owner = (((! $top_level_post) && ($target_item['item_flags'] & ITEM_ORIGIN) && comment_local_origin()) + ? true + : false + ); $uplink = false; -- cgit v1.2.3 From ac3384e661115fac5d771f62fc3eaa1587e5326f Mon Sep 17 00:00:00 2001 From: friendica Date: Wed, 25 Feb 2015 17:24:09 -0800 Subject: syntax - missing arg --- include/notifier.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'include/notifier.php') diff --git a/include/notifier.php b/include/notifier.php index 22adc78a3..36a52b209 100644 --- a/include/notifier.php +++ b/include/notifier.php @@ -375,7 +375,7 @@ function notifier_run($argv, $argc){ // flag on comments for an extended period. So we'll also call comment_local_origin() which looks at // the hostname in the message_id and provides a second (fallback) opinion. - $relay_to_owner = (((! $top_level_post) && ($target_item['item_flags'] & ITEM_ORIGIN) && comment_local_origin()) + $relay_to_owner = (((! $top_level_post) && ($target_item['item_flags'] & ITEM_ORIGIN) && comment_local_origin($target_item)) ? true : false ); -- cgit v1.2.3 From 2b44c5fc72ac1a76b0a711d459ddcb52ed6666dc Mon Sep 17 00:00:00 2001 From: friendica Date: Fri, 27 Feb 2015 13:43:12 -0800 Subject: Fix a couple of places where we weren't checking for dead hublocs. Add a function to mark a hubloc dead. --- include/notifier.php | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) (limited to 'include/notifier.php') diff --git a/include/notifier.php b/include/notifier.php index 36a52b209..a9c4905ae 100644 --- a/include/notifier.php +++ b/include/notifier.php @@ -100,10 +100,14 @@ function notifier_run($argv, $argc){ // Get the recipient $r = q("select abook.*, hubloc.* from abook left join hubloc on hubloc_hash = abook_xchan - where abook_id = %d and not ( abook_flags & %d )>0 limit 1", + where abook_id = %d and not ( abook_flags & %d ) > 0 + and not (hubloc_flags & %d) > 0 and not (hubloc_status & %d) > 0 limit 1", intval($item_id), - intval(ABOOK_FLAG_SELF) + intval(ABOOK_FLAG_SELF), + intval(HUBLOC_FLAGS_DELETED), + intval(HUBLOC_OFFLINE) ); + if($r) { // Get the sender $s = q("select * from channel left join xchan on channel_hash = xchan_hash where channel_id = %d limit 1", @@ -116,8 +120,11 @@ function notifier_run($argv, $argc){ } else { // send a refresh message to each hub they have registered here - $h = q("select * from hubloc where hubloc_hash = '%s'", - dbesc($r[0]['hubloc_hash']) + $h = q("select * from hubloc where hubloc_hash = '%s' + and not (hubloc_flags & %d) > 0 and not (hubloc_status & %d) > 0", + dbesc($r[0]['hubloc_hash']), + intval(HUBLOC_FLAGS_DELETED), + intval(HUBLOC_OFFLINE) ); if($h) { foreach($h as $hh) { @@ -138,7 +145,6 @@ function notifier_run($argv, $argc){ } } } - return; } @@ -491,6 +497,9 @@ function notifier_run($argv, $argc){ logger('notifier: hub choice: ' . intval($relay_to_owner) . ' ' . intval($private) . ' ' . $cmd, LOGGER_DEBUG); + // FIXME: I think we need to remove the private bit or this clause will never execute. Needs more coffee to think it through. + // We may in fact have to send it to clones in case the one we pick recently died. + if($relay_to_owner && (! $private) && ($cmd !== 'relay')) { // If sending a followup to the post owner, only send it to one channel clone - to avoid race conditions. -- cgit v1.2.3 From 0134a41015dd79092cb6a42ad0f7122d0af9bc6d Mon Sep 17 00:00:00 2001 From: friendica Date: Mon, 9 Mar 2015 19:57:35 -0700 Subject: more work on queue optimisations --- include/notifier.php | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) (limited to 'include/notifier.php') diff --git a/include/notifier.php b/include/notifier.php index a9c4905ae..bec18142a 100644 --- a/include/notifier.php +++ b/include/notifier.php @@ -135,10 +135,25 @@ function notifier_run($argv, $argc){ )); if($data) { $result = zot_zot($hh['hubloc_callback'],$data); -// zot_queue_item is not yet written -// if(! $result['success']) -// zot_queue_item(); + // if immediate delivery failed, stick it in the queue to try again later. + + if(! $result['success']) { + $hash = random_string(); + q("insert into outq ( outq_hash, outq_account, outq_channel, outq_driver, outq_posturl, outq_async, outq_created, outq_updated, outq_notify, outq_msg ) + values ( '%s', %d, %d, '%s', '%s', %d, '%s', '%s', '%s', '%s' )", + dbesc($hash), + intval($s[0]['channel_account_id']), + intval($s[0]['channel_id']), + dbesc('zot'), + dbesc($hh['hubloc_callback']), + intval(1), + dbesc(datetime_convert()), + dbesc(datetime_convert()), + dbesc($data), + dbesc('') + ); + } } } } -- cgit v1.2.3