Move the contact discovery into the background

This commit is contained in:
Michael Vogel 2015-07-26 14:41:34 +02:00
parent fc9c6e6bfd
commit 166519fc4d
3 changed files with 41 additions and 17 deletions

View file

@ -38,23 +38,26 @@ function discover_poco_run(&$argv, &$argc){
if(($argc > 2) && ($argv[1] == "dirsearch")) { if(($argc > 2) && ($argv[1] == "dirsearch")) {
$search = urldecode($argv[2]); $search = urldecode($argv[2]);
$searchmode = 1; $mode = 1;
} elseif(($argc == 2) && ($argv[1] == "checkcontact")) {
$mode = 2;
} elseif ($argc == 1) { } elseif ($argc == 1) {
$search = ""; $search = "";
$searchmode = 0; $mode = 0;
} else } else
die("Unknown or missing parameter ".$argv[1]."\n"); die("Unknown or missing parameter ".$argv[1]."\n");
$lockpath = get_lockpath(); $lockpath = get_lockpath();
if ($lockpath != '') { if ($lockpath != '') {
$pidfile = new pidfile($lockpath, 'discover_poco'.urlencode($search)); $pidfile = new pidfile($lockpath, 'discover_poco'.$mode.urlencode($search));
if($pidfile->is_already_running()) { if($pidfile->is_already_running()) {
logger("discover_poco: Already running"); logger("discover_poco: Already running");
if ($pidfile->running_time() > 19*60) { if ($pidfile->running_time() > 19*60) {
$pidfile->kill(); $pidfile->kill();
logger("discover_poco: killed stale process"); logger("discover_poco: killed stale process");
// Calling a new instance // Calling a new instance
proc_run('php','include/discover_poco.php'); if ($mode == 0)
proc_run('php','include/discover_poco.php');
} }
exit; exit;
} }
@ -66,9 +69,11 @@ function discover_poco_run(&$argv, &$argc){
logger('start '.$search); logger('start '.$search);
if (($search != "") and get_config('system','poco_local_search')) if (($mode == 2) AND get_config('system','poco_completion'))
discover_users();
elseif (($mode == 1) AND ($search != "") and get_config('system','poco_local_search'))
discover_directory($search); discover_directory($search);
elseif (($search == "") and get_config('system','poco_discovery') > 0) elseif (($mode == 0) AND ($search == "") and (get_config('system','poco_discovery') > 0))
poco_discover(); poco_discover();
logger('end '.$search); logger('end '.$search);
@ -76,6 +81,21 @@ function discover_poco_run(&$argv, &$argc){
return; return;
} }
function discover_users() {
$users = q("SELECT `url` FROM `gcontact` WHERE `updated` = '0000-00-00 00:00:00' AND
`last_contact` = '0000-00-00 00:00:00' AND `last_failure` = '0000-00-00 00:00:00' AND
`network` IN ('%s', '%s', '%s') ORDER BY rand() LIMIT 50",
dbesc(NETWORK_DFRN), dbesc(NETWORK_DIASPORA), dbesc(NETWORK_OSTATUS));
if (!$users)
return;
foreach ($users AS $user) {
logger('Check user '.$user["url"]);
poco_last_updated($user["url"]);
}
}
function discover_directory($search) { function discover_directory($search) {
$data = Cache::get("dirsearch:".$search); $data = Cache::get("dirsearch:".$search);

View file

@ -86,6 +86,10 @@ function poller_run(&$argv, &$argc){
proc_run('php',"include/discover_poco.php"); proc_run('php',"include/discover_poco.php");
// run the process to update locally stored global contacts in the background
proc_run('php',"include/discover_poco.php", "checkcontact");
// expire any expired accounts // expire any expired accounts
q("UPDATE user SET `account_expired` = 1 where `account_expired` = 0 q("UPDATE user SET `account_expired` = 1 where `account_expired` = 0

View file

@ -266,17 +266,17 @@ function poco_check($profile_url, $name, $network, $profile_photo, $about, $loca
poco_check_server($server_url, $network); poco_check_server($server_url, $network);
// Fetch last update manually if it is enabled in the system // Fetch last update manually if it is enabled in the system
if (get_config('system','poco_completion') AND ($orig_updated == "0000-00-00 00:00:00") //if (get_config('system','poco_completion') AND ($orig_updated == "0000-00-00 00:00:00")
AND poco_do_update($created, $updated, $last_failure, $last_contact) // AND poco_do_update($created, $updated, $last_failure, $last_contact)
AND poco_reachable($profile_url, $server_url, $network)) { // AND poco_reachable($profile_url, $server_url, $network)) {
$last_updated = poco_last_updated($profile_url); // $last_updated = poco_last_updated($profile_url);
if ($last_updated) { // if ($last_updated) {
$updated = $last_updated; // $updated = $last_updated;
$last_contact = datetime_convert(); // $last_contact = datetime_convert();
logger("Last updated for profile ".$profile_url.": ".$updated, LOGGER_DEBUG); // logger("Last updated for profile ".$profile_url.": ".$updated, LOGGER_DEBUG);
} else // } else
$last_failure = datetime_convert(); // $last_failure = datetime_convert();
} //}
if(count($x)) { if(count($x)) {
$gcid = $x[0]['id']; $gcid = $x[0]['id'];