1
1
Fork 0

Split the POCO discovery process in several small processes

This commit is contained in:
Michael 2017-03-19 17:43:59 +00:00
parent 7f61b2ee15
commit 2615d40d6b
2 changed files with 19 additions and 11 deletions

View file

@ -27,6 +27,8 @@ function discover_poco_run(&$argv, &$argc) {
$mode = 4;
} elseif (($argc == 2) && ($argv[1] == "update_server")) {
$mode = 5;
} elseif (($argc == 3) && ($argv[1] == "update_server_directory")) {
$mode = 6;
} elseif ($argc == 1) {
$search = "";
$mode = 0;
@ -36,7 +38,9 @@ function discover_poco_run(&$argv, &$argc) {
logger('start '.$search);
if ($mode == 5) {
if ($mode == 6) {
poco_discover_single_server(intval($argv[2]));
} elseif ($mode == 5) {
update_server();
} elseif ($mode == 4) {
$server_url = base64_decode($argv[2]);

View file

@ -1676,19 +1676,13 @@ function poco_discover_single_server($id) {
$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"]));
return false;
}
// Discover new servers out there
// Discover new servers out there (Works from Friendica version 3.5.2)
poco_fetch_serverlist($server["poco"]);
// Fetch all users from the other server
$url = $server["poco"]."/?fields=displayName,urls,photos,updated,network,aboutMe,currentLocation,tags,gender,contactType,generation";
logger("Fetch all users from the server ".$server["nurl"], LOGGER_DEBUG);
logger("Fetch all users from the server ".$server["url"], LOGGER_DEBUG);
$retdata = z_fetch_url($url);
if ($retdata["success"]) {
@ -1750,10 +1744,20 @@ function poco_discover($complete = false) {
$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));
$r = q("SELECT `id`, `url`, `network` 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)) {
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;
}
logger('Update directory from server '.$server['url'].' with ID '.$server['id'], LOGGER_DEBUG);
proc_run(PRIORITY_LOW, "include/discover_poco.php", "update_server_directory", $server['id']);
if (!$complete AND (--$no_of_queries == 0)) {
break;
}
}