Split poco discovery in smaller function calls

This commit is contained in:
Michael 2017-01-27 17:00:34 +00:00
parent 722b18ead7
commit 2a77e426f9

View file

@ -1260,28 +1260,18 @@ function poco_discover_federation() {
set_config('poco','last_federation_discovery', time());
}
function poco_discover($complete = false) {
function poco_discover_single_server($id) {
$r = q("SELECT `poco`, `nurl`, `url`, `network` FROM `gserver` WHERE `id` = %d", intval($id));
if (!dbm::is_result($r)) {
return false;
}
// Update the server list
poco_discover_federation();
$no_of_queries = 5;
$requery_days = intval(get_config("system", "poco_requery_days"));
if ($requery_days == 0)
$requery_days = 7;
$last_update = date("c", time() - (60 * 60 * 24 * $requery_days));
$r = q("SELECT `poco`, `nurl`, `url`, `network` FROM `gserver` WHERE `last_contact` >= `last_failure` AND `poco` != '' AND `last_poco_query` < '%s' ORDER BY RAND()", dbesc($last_update));
if ($r)
foreach ($r AS $server) {
$server = $r[0];
if (!poco_check_server($server["url"], $server["network"])) {
// The server is not reachable? Okay, then we will try it later
q("UPDATE `gserver` SET `last_poco_query` = '%s' WHERE `nurl` = '%s'", dbesc(datetime_convert()), dbesc($server["nurl"]));
continue;
return false;
}
// Fetch all users from the other server
@ -1298,8 +1288,9 @@ function poco_discover($complete = false) {
if (get_config('system','poco_discovery') > 1) {
$timeframe = get_config('system','poco_discovery_since');
if ($timeframe == 0)
if ($timeframe == 0) {
$timeframe = 30;
}
$updatedSince = date("Y-m-d H:i:s", time() - $timeframe * 86400);
@ -1321,14 +1312,39 @@ function poco_discover($complete = false) {
}
q("UPDATE `gserver` SET `last_poco_query` = '%s' WHERE `nurl` = '%s'", dbesc(datetime_convert()), dbesc($server["nurl"]));
if (!$complete AND (--$no_of_queries == 0))
break;
return true;
} else {
// If the server hadn't replied correctly, then force a sanity check
poco_check_server($server["url"], $server["network"], true);
// If we couldn't reach the server, we will try it some time later
q("UPDATE `gserver` SET `last_poco_query` = '%s' WHERE `nurl` = '%s'", dbesc(datetime_convert()), dbesc($server["nurl"]));
return false;
}
}
function poco_discover($complete = false) {
// Update the server list
poco_discover_federation();
$no_of_queries = 5;
$requery_days = intval(get_config("system", "poco_requery_days"));
if ($requery_days == 0)
$requery_days = 7;
$last_update = date("c", time() - (60 * 60 * 24 * $requery_days));
$r = q("SELECT `id` FROM `gserver` WHERE `last_contact` >= `last_failure` AND `poco` != '' AND `last_poco_query` < '%s' ORDER BY RAND()", dbesc($last_update));
if (dbm::is_result($r)) {
foreach ($r AS $server) {
if (poco_discover_single_server($server['id']) AND !$complete AND (--$no_of_queries == 0)) {
break;
}
}
}
}