Optimized query for nodeinfo, better way to analyze posting problems with DFRN

This commit is contained in:
Michael 2017-02-04 16:16:15 +00:00
parent 5ffef9c96d
commit 9c4a53e380
4 changed files with 38 additions and 34 deletions

View file

@ -398,7 +398,7 @@ function delivery_run(&$argv, &$argc){
logger('notifier: dfrn_delivery to '.$contact["url"].' with guid '.$target_item["guid"].' returns '.$deliver_status); logger('notifier: dfrn_delivery to '.$contact["url"].' with guid '.$target_item["guid"].' returns '.$deliver_status);
if ($deliver_status == (-1)) { if ($deliver_status < 0) {
logger('notifier: delivery failed: queuing message'); logger('notifier: delivery failed: queuing message');
add_to_queue($contact['id'],NETWORK_DFRN,$atom); add_to_queue($contact['id'],NETWORK_DFRN,$atom);

View file

@ -916,14 +916,14 @@ class dfrn {
$ret = z_fetch_url($url); $ret = z_fetch_url($url);
if ($ret['errno'] == CURLE_OPERATION_TIMEDOUT) { if ($ret['errno'] == CURLE_OPERATION_TIMEDOUT) {
return(-1); // timed out return -2; // timed out
} }
$xml = $ret['body']; $xml = $ret['body'];
$curl_stat = $a->get_curl_code(); $curl_stat = $a->get_curl_code();
if(! $curl_stat) if(! $curl_stat)
return(-1); // timed out return -3; // timed out
logger('dfrn_deliver: ' . $xml, LOGGER_DATA); logger('dfrn_deliver: ' . $xml, LOGGER_DATA);
@ -1023,24 +1023,24 @@ class dfrn {
$key = Crypto::createNewRandomKey(); $key = Crypto::createNewRandomKey();
} catch (CryptoTestFailed $ex) { } catch (CryptoTestFailed $ex) {
logger('Cannot safely create a key'); logger('Cannot safely create a key');
return -1; return -4;
} catch (CannotPerformOperation $ex) { } catch (CannotPerformOperation $ex) {
logger('Cannot safely create a key'); logger('Cannot safely create a key');
return -1; return -5;
} }
try { try {
$data = Crypto::encrypt($postvars['data'], $key); $data = Crypto::encrypt($postvars['data'], $key);
} catch (CryptoTestFailed $ex) { } catch (CryptoTestFailed $ex) {
logger('Cannot safely perform encryption'); logger('Cannot safely perform encryption');
return -1; return -6;
} catch (CannotPerformOperation $ex) { } catch (CannotPerformOperation $ex) {
logger('Cannot safely perform encryption'); logger('Cannot safely perform encryption');
return -1; return -7;
} }
break; break;
default: default:
logger("rino: invalid requested verision '$rino_remote_version'"); logger("rino: invalid requested verision '$rino_remote_version'");
return -1; return -8;
} }
$postvars['rino'] = $rino_remote_version; $postvars['rino'] = $rino_remote_version;
@ -1074,16 +1074,16 @@ class dfrn {
logger('dfrn_deliver: ' . "SENDING: " . print_r($postvars,true), LOGGER_DATA); logger('dfrn_deliver: ' . "SENDING: " . print_r($postvars,true), LOGGER_DATA);
$xml = post_url($contact['notify'],$postvars); $xml = post_url($contact['notify'], $postvars);
logger('dfrn_deliver: ' . "RECEIVED: " . $xml, LOGGER_DATA); logger('dfrn_deliver: ' . "RECEIVED: " . $xml, LOGGER_DATA);
$curl_stat = $a->get_curl_code(); $curl_stat = $a->get_curl_code();
if((! $curl_stat) || (! strlen($xml))) if((! $curl_stat) || (! strlen($xml)))
return(-1); // timed out return -9; // timed out
if(($curl_stat == 503) && (stristr($a->get_curl_headers(),'retry-after'))) if(($curl_stat == 503) && (stristr($a->get_curl_headers(),'retry-after')))
return(-1); return -10;
if(strpos($xml,'<?xml') === false) { if(strpos($xml,'<?xml') === false) {
logger('dfrn_deliver: phase 2: no valid XML returned'); logger('dfrn_deliver: phase 2: no valid XML returned');

View file

@ -38,10 +38,11 @@ function queue_run(&$argv, &$argc){
load_hooks(); load_hooks();
if($argc > 1) if ($argc > 1) {
$queue_id = intval($argv[1]); $queue_id = intval($argv[1]);
else } else {
$queue_id = 0; $queue_id = 0;
}
$cachekey_deadguy = 'queue_run:deadguy:'; $cachekey_deadguy = 'queue_run:deadguy:';
$cachekey_server = 'queue_run:server:'; $cachekey_server = 'queue_run:server:';
@ -64,7 +65,7 @@ function queue_run(&$argv, &$argc){
foreach ($r as $rr) { foreach ($r as $rr) {
logger('queue: deliverq'); logger('queue: deliverq');
proc_run(PRIORITY_HIGH,'include/delivery.php',$rr['cmd'],$rr['item'],$rr['contact']); proc_run(PRIORITY_HIGH,'include/delivery.php',$rr['cmd'],$rr['item'],$rr['contact']);
if($interval) { if ($interval) {
time_sleep_until(microtime(true) + (float) $interval); time_sleep_until(microtime(true) + (float) $interval);
} }
} }
@ -111,10 +112,10 @@ function queue_run(&$argv, &$argc){
// queue_predeliver hooks may have changed the queue db details, // queue_predeliver hooks may have changed the queue db details,
// so check again if this entry still needs processing // so check again if this entry still needs processing
if($queue_id) if ($queue_id) {
$qi = q("SELECT * FROM `queue` WHERE `id` = %d LIMIT 1", $qi = q("SELECT * FROM `queue` WHERE `id` = %d LIMIT 1",
intval($queue_id)); intval($queue_id));
elseif (get_config("system", "worker")) { } elseif (get_config("system", "worker")) {
logger('Call queue for id '.$q_item['id']); logger('Call queue for id '.$q_item['id']);
proc_run(PRIORITY_LOW, "include/queue.php", $q_item['id']); proc_run(PRIORITY_LOW, "include/queue.php", $q_item['id']);
continue; continue;
@ -122,8 +123,9 @@ function queue_run(&$argv, &$argc){
$qi = q("SELECT * FROM `queue` WHERE `id` = %d AND `last` < UTC_TIMESTAMP() - INTERVAL 15 MINUTE ", $qi = q("SELECT * FROM `queue` WHERE `id` = %d AND `last` < UTC_TIMESTAMP() - INTERVAL 15 MINUTE ",
intval($q_item['id'])); intval($q_item['id']));
if(! count($qi)) if (!dbm::is_result($qi)) {
continue; continue;
}
$c = q("SELECT * FROM `contact` WHERE `id` = %d LIMIT 1", $c = q("SELECT * FROM `contact` WHERE `id` = %d LIMIT 1",
@ -182,36 +184,37 @@ function queue_run(&$argv, &$argc){
logger('queue: dfrndelivery: item '.$q_item['id'].' for '.$contact['name'].' <'.$contact['url'].'>'); logger('queue: dfrndelivery: item '.$q_item['id'].' for '.$contact['name'].' <'.$contact['url'].'>');
$deliver_status = dfrn::deliver($owner,$contact,$data); $deliver_status = dfrn::deliver($owner,$contact,$data);
if($deliver_status == (-1)) { if ($deliver_status < 0) {
update_queue_time($q_item['id']); update_queue_time($q_item['id']);
Cache::set($cachekey_deadguy.$contact['notify'], true, CACHE_QUARTER_HOUR); Cache::set($cachekey_deadguy.$contact['notify'], true, CACHE_QUARTER_HOUR);
} else } else {
remove_queue_item($q_item['id']); remove_queue_item($q_item['id']);
}
break; break;
case NETWORK_OSTATUS: case NETWORK_OSTATUS:
if($contact['notify']) { if ($contact['notify']) {
logger('queue: slapdelivery: item '.$q_item['id'].' for '.$contact['name'].' <'.$contact['url'].'>'); logger('queue: slapdelivery: item '.$q_item['id'].' for '.$contact['name'].' <'.$contact['url'].'>');
$deliver_status = slapper($owner,$contact['notify'],$data); $deliver_status = slapper($owner,$contact['notify'],$data);
if($deliver_status == (-1)) { if ($deliver_status == (-1)) {
update_queue_time($q_item['id']); update_queue_time($q_item['id']);
Cache::set($cachekey_deadguy.$contact['notify'], true, CACHE_QUARTER_HOUR); Cache::set($cachekey_deadguy.$contact['notify'], true, CACHE_QUARTER_HOUR);
} else } else {
remove_queue_item($q_item['id']); remove_queue_item($q_item['id']);
}
} }
break; break;
case NETWORK_DIASPORA: case NETWORK_DIASPORA:
if($contact['notify']) { if ($contact['notify']) {
logger('queue: diaspora_delivery: item '.$q_item['id'].' for '.$contact['name'].' <'.$contact['url'].'>'); logger('queue: diaspora_delivery: item '.$q_item['id'].' for '.$contact['name'].' <'.$contact['url'].'>');
$deliver_status = Diaspora::transmit($owner,$contact,$data,$public,true); $deliver_status = Diaspora::transmit($owner,$contact,$data,$public,true);
if($deliver_status == (-1)) { if ($deliver_status == (-1)) {
update_queue_time($q_item['id']); update_queue_time($q_item['id']);
Cache::set($cachekey_deadguy.$contact['notify'], true, CACHE_QUARTER_HOUR); Cache::set($cachekey_deadguy.$contact['notify'], true, CACHE_QUARTER_HOUR);
} else } else {
remove_queue_item($q_item['id']); remove_queue_item($q_item['id']);
}
} }
break; break;
@ -219,15 +222,15 @@ function queue_run(&$argv, &$argc){
$params = array('owner' => $owner, 'contact' => $contact, 'queue' => $q_item, 'result' => false); $params = array('owner' => $owner, 'contact' => $contact, 'queue' => $q_item, 'result' => false);
call_hooks('queue_deliver', $a, $params); call_hooks('queue_deliver', $a, $params);
if($params['result']) if ($params['result']) {
remove_queue_item($q_item['id']); remove_queue_item($q_item['id']);
else } else {
update_queue_time($q_item['id']); update_queue_time($q_item['id']);
}
break; break;
} }
logger('Deliver status '.$deliver_status.' for item '.$q_item['id'].' to '.$contact['name'].' <'.$contact['url'].'>'); logger('Deliver status '.(int)$deliver_status.' for item '.$q_item['id'].' to '.$contact['name'].' <'.$contact['url'].'>');
} }
return; return;

View file

@ -228,9 +228,10 @@ function nodeinfo_cron() {
logger("local_posts: ".$local_posts, LOGGER_DEBUG); logger("local_posts: ".$local_posts, LOGGER_DEBUG);
$posts = qu("SELECT COUNT(*) AS `local_comments` FROM `item` $posts = qu("SELECT COUNT(*) FROM `contact`
INNER JOIN `contact` ON `contact`.`id` = `item`.`contact-id` INNER JOIN `item` ON `item`.`contact-id` = `contact`.`id` AND `item`.`uid` = `contact`.`uid` AND
WHERE `contact`.`self` and `item`.`id` != `item`.`parent` AND `item`.`network` IN ('%s', '%s', '%s')", `item`.`id` != `item`.`parent` AND `item`.`network` IN ('%s', '%s', '%s')
WHERE `contact`.`self`",
dbesc(NETWORK_OSTATUS), dbesc(NETWORK_DIASPORA), dbesc(NETWORK_DFRN)); dbesc(NETWORK_OSTATUS), dbesc(NETWORK_DIASPORA), dbesc(NETWORK_DFRN));
if (!is_array($posts)) if (!is_array($posts))