Merge pull request #8901 from annando/failed
New field in gserver, gcontact and contact for failed connections
This commit is contained in:
commit
31d2a74b0b
15 changed files with 123 additions and 64 deletions
|
@ -1029,7 +1029,7 @@ class Contact
|
|||
{
|
||||
// Always unarchive the relay contact entry
|
||||
if (!empty($contact['batch']) && !empty($contact['term-date']) && ($contact['term-date'] > DBA::NULL_DATETIME)) {
|
||||
$fields = ['term-date' => DBA::NULL_DATETIME, 'archive' => false];
|
||||
$fields = ['failed' => false, 'term-date' => DBA::NULL_DATETIME, 'archive' => false];
|
||||
$condition = ['uid' => 0, 'network' => Protocol::FEDERATED, 'batch' => $contact['batch'], 'contact-type' => self::TYPE_RELAY];
|
||||
DBA::update('contact', $fields, $condition);
|
||||
}
|
||||
|
@ -1053,7 +1053,7 @@ class Contact
|
|||
}
|
||||
|
||||
// It's a miracle. Our dead contact has inexplicably come back to life.
|
||||
$fields = ['term-date' => DBA::NULL_DATETIME, 'archive' => false];
|
||||
$fields = ['failed' => false, 'term-date' => DBA::NULL_DATETIME, 'archive' => false];
|
||||
DBA::update('contact', $fields, ['id' => $contact['id']]);
|
||||
DBA::update('contact', $fields, ['nurl' => Strings::normaliseLink($contact['url']), 'self' => false]);
|
||||
GContact::updateFromPublicContactURL($contact['url']);
|
||||
|
@ -1495,7 +1495,8 @@ class Contact
|
|||
$updated = [
|
||||
'url' => $data['url'],
|
||||
'nurl' => Strings::normaliseLink($data['url']),
|
||||
'updated' => DateTimeFormat::utcNow()
|
||||
'updated' => DateTimeFormat::utcNow(),
|
||||
'failed' => false
|
||||
];
|
||||
|
||||
$fields = ['addr', 'alias', 'name', 'nick', 'keywords', 'location', 'about', 'baseurl', 'gsid'];
|
||||
|
@ -1973,7 +1974,7 @@ class Contact
|
|||
// We check after the probing to be able to correct falsely detected contact types.
|
||||
if (($contact['contact-type'] == self::TYPE_RELAY) &&
|
||||
(!Strings::compareLink($ret['url'], $contact['url']) || in_array($ret['network'], [Protocol::FEED, Protocol::PHANTOM]))) {
|
||||
self::updateContact($id, $uid, $contact['url'], ['last-update' => $updated, 'success_update' => $updated]);
|
||||
self::updateContact($id, $uid, $contact['url'], ['failed' => false, 'last-update' => $updated, 'success_update' => $updated]);
|
||||
Logger::info('Not updating relais', ['id' => $id, 'url' => $contact['url']]);
|
||||
return true;
|
||||
}
|
||||
|
@ -1981,7 +1982,7 @@ class Contact
|
|||
// If Probe::uri fails the network code will be different ("feed" or "unkn")
|
||||
if (in_array($ret['network'], [Protocol::FEED, Protocol::PHANTOM]) && ($ret['network'] != $contact['network'])) {
|
||||
if ($force && ($uid == 0)) {
|
||||
self::updateContact($id, $uid, $ret['url'], ['last-update' => $updated, 'failure_update' => $updated]);
|
||||
self::updateContact($id, $uid, $ret['url'], ['failed' => true, 'last-update' => $updated, 'failure_update' => $updated]);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
@ -2025,7 +2026,7 @@ class Contact
|
|||
|
||||
if (!$update) {
|
||||
if ($force) {
|
||||
self::updateContact($id, $uid, $ret['url'], ['last-update' => $updated, 'success_update' => $updated]);
|
||||
self::updateContact($id, $uid, $ret['url'], ['failed' => false, 'last-update' => $updated, 'success_update' => $updated]);
|
||||
}
|
||||
|
||||
// Update the public contact
|
||||
|
@ -2055,6 +2056,7 @@ class Contact
|
|||
if ($force && ($uid == 0)) {
|
||||
$ret['last-update'] = $updated;
|
||||
$ret['success_update'] = $updated;
|
||||
$ret['failed'] = false;
|
||||
}
|
||||
|
||||
unset($ret['photo']);
|
||||
|
|
|
@ -95,7 +95,7 @@ class GContact
|
|||
|
||||
$results = DBA::p("SELECT `nurl` FROM `gcontact`
|
||||
WHERE NOT `hide` AND `network` IN (?, ?, ?, ?) AND
|
||||
((`last_contact` >= `last_failure`) OR (`updated` >= `last_failure`)) AND
|
||||
NOT `failed` AND
|
||||
(`addr` LIKE ? OR `name` LIKE ? OR `nick` LIKE ?) $extra_sql
|
||||
GROUP BY `nurl` ORDER BY `nurl` DESC LIMIT 1000",
|
||||
Protocol::DFRN, Protocol::ACTIVITYPUB, $ostatus, $diaspora, $search, $search, $search
|
||||
|
@ -231,6 +231,7 @@ class GContact
|
|||
}
|
||||
|
||||
$gcontact['server_url'] = $data['baseurl'];
|
||||
$gcontact['failed'] = false;
|
||||
|
||||
$gcontact = array_merge($gcontact, $data);
|
||||
}
|
||||
|
@ -273,8 +274,7 @@ class GContact
|
|||
"SELECT count(*) as `total`
|
||||
FROM `glink` INNER JOIN `gcontact` on `glink`.`gcid` = `gcontact`.`id`
|
||||
WHERE `glink`.`cid` = %d AND `glink`.`uid` = %d AND
|
||||
((`gcontact`.`last_contact` >= `gcontact`.`last_failure`) OR
|
||||
(`gcontact`.`updated` >= `gcontact`.`last_failure`))
|
||||
NOT `gcontact`.`failed`
|
||||
AND `gcontact`.`nurl` IN (select nurl from contact where uid = %d and self = 0 and blocked = 0 and hidden = 0 and id != %d) ",
|
||||
intval($cid),
|
||||
intval($uid),
|
||||
|
@ -337,7 +337,7 @@ class GContact
|
|||
WHERE `glink`.`cid` = %d and `glink`.`uid` = %d
|
||||
AND `contact`.`uid` = %d AND `contact`.`self` = 0 AND `contact`.`blocked` = 0
|
||||
AND `contact`.`hidden` = 0 AND `contact`.`id` != %d
|
||||
AND ((`gcontact`.`last_contact` >= `gcontact`.`last_failure`) OR (`gcontact`.`updated` >= `gcontact`.`last_failure`))
|
||||
AND NOT `gcontact`.`failed`
|
||||
$sql_extra LIMIT %d, %d",
|
||||
intval($cid),
|
||||
intval($uid),
|
||||
|
@ -396,7 +396,7 @@ class GContact
|
|||
"SELECT count(*) as `total`
|
||||
FROM `glink` INNER JOIN `gcontact` on `glink`.`gcid` = `gcontact`.`id`
|
||||
where `glink`.`cid` = %d and `glink`.`uid` = %d AND
|
||||
((`gcontact`.`last_contact` >= `gcontact`.`last_failure`) OR (`gcontact`.`updated` >= `gcontact`.`last_failure`))",
|
||||
NOT `gcontact`.`failed`",
|
||||
intval($cid),
|
||||
intval($uid)
|
||||
);
|
||||
|
@ -424,7 +424,7 @@ class GContact
|
|||
INNER JOIN `gcontact` on `glink`.`gcid` = `gcontact`.`id`
|
||||
LEFT JOIN `contact` ON `contact`.`nurl` = `gcontact`.`nurl` AND `contact`.`uid` = %d
|
||||
WHERE `glink`.`cid` = %d AND `glink`.`uid` = %d AND
|
||||
((`gcontact`.`last_contact` >= `gcontact`.`last_failure`) OR (`gcontact`.`updated` >= `gcontact`.`last_failure`))
|
||||
NOT `gcontact`.`failed`
|
||||
ORDER BY `gcontact`.`name` ASC LIMIT %d, %d ",
|
||||
intval($uid),
|
||||
intval($cid),
|
||||
|
@ -471,7 +471,7 @@ class GContact
|
|||
AND NOT `gcontact`.`name` IN (SELECT `name` FROM `contact` WHERE `uid` = %d)
|
||||
AND NOT `gcontact`.`id` IN (SELECT `gcid` FROM `gcign` WHERE `uid` = %d)
|
||||
AND `gcontact`.`updated` >= '%s' AND NOT `gcontact`.`hide`
|
||||
AND `gcontact`.`last_contact` >= `gcontact`.`last_failure`
|
||||
AND NOT `gcontact`.`failed`
|
||||
AND `gcontact`.`network` IN (%s)
|
||||
GROUP BY `glink`.`gcid` ORDER BY `gcontact`.`updated` DESC,`total` DESC LIMIT %d, %d",
|
||||
intval($uid),
|
||||
|
@ -495,7 +495,7 @@ class GContact
|
|||
AND NOT `gcontact`.`name` IN (SELECT `name` FROM `contact` WHERE `uid` = %d)
|
||||
AND NOT `gcontact`.`id` IN (SELECT `gcid` FROM `gcign` WHERE `uid` = %d)
|
||||
AND `gcontact`.`updated` >= '%s'
|
||||
AND `gcontact`.`last_contact` >= `gcontact`.`last_failure`
|
||||
AND NOT `gcontact`.`failed`
|
||||
AND `gcontact`.`network` IN (%s)
|
||||
ORDER BY rand() LIMIT %d, %d",
|
||||
intval($uid),
|
||||
|
@ -642,7 +642,7 @@ class GContact
|
|||
$fields = ['name' => $contact['name'], 'nick' => $contact['nick'] ?? '', 'addr' => $contact['addr'] ?? '', 'network' => $contact['network'],
|
||||
'url' => $contact['url'], 'nurl' => Strings::normaliseLink($contact['url']), 'photo' => $contact['photo'],
|
||||
'created' => DateTimeFormat::utcNow(), 'updated' => DateTimeFormat::utcNow(), 'location' => $contact['location'],
|
||||
'about' => $contact['about'], 'hide' => $contact['hide'], 'generation' => $contact['generation']];
|
||||
'about' => $contact['about'], 'hide' => $contact['hide'], 'generation' => $contact['generation'], 'failed' => false];
|
||||
|
||||
DBA::insert('gcontact', $fields);
|
||||
|
||||
|
@ -681,7 +681,7 @@ class GContact
|
|||
}
|
||||
|
||||
$public_contact = DBA::selectFirst('gcontact', [
|
||||
'name', 'nick', 'photo', 'location', 'about', 'addr', 'generation', 'birthday', 'keywords', 'gsid',
|
||||
'name', 'nick', 'photo', 'location', 'about', 'addr', 'generation', 'birthday', 'keywords', 'gsid', 'failed',
|
||||
'contact-type', 'hide', 'nsfw', 'network', 'alias', 'notify', 'server_url', 'connect', 'updated', 'url'
|
||||
], ['id' => $gcontact_id]);
|
||||
|
||||
|
@ -787,7 +787,7 @@ class GContact
|
|||
'location' => $contact['location'], 'about' => $contact['about'],
|
||||
'generation' => $contact['generation'], 'updated' => $contact['updated'],
|
||||
'server_url' => $contact['server_url'], 'connect' => $contact['connect'],
|
||||
'gsid' => $contact['gsid']
|
||||
'failed' => $contact['failed'], 'gsid' => $contact['gsid']
|
||||
];
|
||||
|
||||
DBA::update('gcontact', $updated, $condition, $fields);
|
||||
|
@ -851,13 +851,13 @@ class GContact
|
|||
$noscrape = json_decode($curlResult->getBody(), true);
|
||||
if (!empty($noscrape) && !empty($noscrape['updated'])) {
|
||||
$noscrape['updated'] = DateTimeFormat::utc($noscrape['updated'], DateTimeFormat::MYSQL);
|
||||
$fields = ['last_contact' => DateTimeFormat::utcNow(), 'updated' => $noscrape['updated']];
|
||||
$fields = ['failed' => false, 'last_contact' => DateTimeFormat::utcNow(), 'updated' => $noscrape['updated']];
|
||||
DBA::update('gcontact', $fields, ['nurl' => Strings::normaliseLink($data['url'])]);
|
||||
return true;
|
||||
}
|
||||
} elseif ($curlResult->isTimeout()) {
|
||||
// On a timeout return the existing value, but mark the contact as failure
|
||||
$fields = ['last_failure' => DateTimeFormat::utcNow()];
|
||||
$fields = ['failed' => true, 'last_failure' => DateTimeFormat::utcNow()];
|
||||
DBA::update('gcontact', $fields, ['nurl' => Strings::normaliseLink($data['url'])]);
|
||||
return true;
|
||||
}
|
||||
|
@ -915,7 +915,7 @@ class GContact
|
|||
return;
|
||||
}
|
||||
|
||||
$fields = ['last_contact' => DateTimeFormat::utcNow(), 'updated' => $last_updated];
|
||||
$fields = ['failed' => false, 'last_contact' => DateTimeFormat::utcNow(), 'updated' => $last_updated];
|
||||
DBA::update('gcontact', $fields, ['nurl' => Strings::normaliseLink($data['url'])]);
|
||||
}
|
||||
|
||||
|
@ -929,7 +929,7 @@ class GContact
|
|||
// Search for the newest entry in the feed
|
||||
$curlResult = Network::curl($data['poll']);
|
||||
if (!$curlResult->isSuccess()) {
|
||||
$fields = ['last_failure' => DateTimeFormat::utcNow()];
|
||||
$fields = ['failed' => true, 'last_failure' => DateTimeFormat::utcNow()];
|
||||
DBA::update('gcontact', $fields, ['nurl' => Strings::normaliseLink($data['url'])]);
|
||||
|
||||
Logger::info("Profile wasn't reachable (no feed)", ['url' => $data['url']]);
|
||||
|
@ -970,7 +970,7 @@ class GContact
|
|||
return;
|
||||
}
|
||||
|
||||
$fields = ['last_contact' => DateTimeFormat::utcNow(), 'updated' => $last_updated];
|
||||
$fields = ['failed' => false, 'last_contact' => DateTimeFormat::utcNow(), 'updated' => $last_updated];
|
||||
DBA::update('gcontact', $fields, ['nurl' => Strings::normaliseLink($data['url'])]);
|
||||
}
|
||||
/**
|
||||
|
@ -1012,7 +1012,7 @@ class GContact
|
|||
$fields = ['name', 'nick', 'url', 'nurl', 'location', 'about', 'keywords',
|
||||
'bd', 'contact-type', 'network', 'addr', 'notify', 'alias', 'archive', 'term-date',
|
||||
'created', 'updated', 'avatar', 'success_update', 'failure_update', 'forum', 'prv',
|
||||
'baseurl', 'gsid', 'sensitive', 'unsearchable'];
|
||||
'baseurl', 'gsid', 'sensitive', 'unsearchable', 'failed'];
|
||||
|
||||
$contact = DBA::selectFirst('contact', $fields, array_merge($condition, ['uid' => 0, 'network' => Protocol::FEDERATED]));
|
||||
if (!DBA::isResult($contact)) {
|
||||
|
@ -1022,7 +1022,7 @@ class GContact
|
|||
$fields = ['name', 'nick', 'url', 'nurl', 'location', 'about', 'keywords', 'generation',
|
||||
'birthday', 'contact-type', 'network', 'addr', 'notify', 'alias', 'archived', 'archive_date',
|
||||
'created', 'updated', 'photo', 'last_contact', 'last_failure', 'community', 'connect',
|
||||
'server_url', 'gsid', 'nsfw', 'hide', 'id'];
|
||||
'server_url', 'gsid', 'nsfw', 'hide', 'id', 'failed'];
|
||||
|
||||
$old_gcontact = DBA::selectFirst('gcontact', $fields, ['nurl' => $contact['nurl']]);
|
||||
$do_insert = !DBA::isResult($old_gcontact);
|
||||
|
@ -1034,7 +1034,7 @@ class GContact
|
|||
|
||||
// These fields are identical in both contact and gcontact
|
||||
$fields = ['name', 'nick', 'url', 'nurl', 'location', 'about', 'keywords', 'gsid',
|
||||
'contact-type', 'network', 'addr', 'notify', 'alias', 'created', 'updated'];
|
||||
'contact-type', 'network', 'addr', 'notify', 'alias', 'created', 'updated', 'failed'];
|
||||
|
||||
foreach ($fields as $field) {
|
||||
$gcontact[$field] = $contact[$field];
|
||||
|
@ -1100,13 +1100,14 @@ class GContact
|
|||
$data = Probe::uri($url, $force);
|
||||
|
||||
if (in_array($data['network'], [Protocol::PHANTOM])) {
|
||||
$fields = ['last_failure' => DateTimeFormat::utcNow()];
|
||||
$fields = ['failed' => true, 'last_failure' => DateTimeFormat::utcNow()];
|
||||
DBA::update('gcontact', $fields, ['nurl' => Strings::normaliseLink($url)]);
|
||||
Logger::info('Invalid network for contact', ['url' => $data['url'], 'callstack' => System::callstack()]);
|
||||
return false;
|
||||
}
|
||||
|
||||
$data['server_url'] = $data['baseurl'];
|
||||
$data['failed'] = false;
|
||||
|
||||
self::update($data);
|
||||
|
||||
|
@ -1268,7 +1269,7 @@ class GContact
|
|||
|
||||
$r = DBA::select('gserver', ['nurl', 'url'], [
|
||||
'`network` = ?
|
||||
AND `last_contact` >= `last_failure`
|
||||
AND NOT `failed`
|
||||
AND `last_poco_query` < ?',
|
||||
Protocol::OSTATUS,
|
||||
$last_update
|
||||
|
@ -1419,8 +1420,8 @@ class GContact
|
|||
public static function getRandomUrl()
|
||||
{
|
||||
$r = DBA::selectFirst('gcontact', ['url'], [
|
||||
'`network` = ?
|
||||
AND `last_contact` >= `last_failure`
|
||||
'`network` = ?
|
||||
AND NOT `failed`
|
||||
AND `updated` > ?',
|
||||
Protocol::DFRN,
|
||||
DateTimeFormat::utc('now - 1 month'),
|
||||
|
|
|
@ -235,14 +235,14 @@ class GServer
|
|||
private static function setFailure(string $url)
|
||||
{
|
||||
if (DBA::exists('gserver', ['nurl' => Strings::normaliseLink($url)])) {
|
||||
DBA::update('gserver', ['last_failure' => DateTimeFormat::utcNow(), 'detection-method' => null],
|
||||
DBA::update('gserver', ['failed' => true, 'last_failure' => DateTimeFormat::utcNow(), 'detection-method' => null],
|
||||
['nurl' => Strings::normaliseLink($url)]);
|
||||
Logger::info('Set failed status for existing server', ['url' => $url]);
|
||||
return;
|
||||
}
|
||||
DBA::insert('gserver', ['url' => $url, 'nurl' => Strings::normaliseLink($url),
|
||||
'network' => Protocol::PHANTOM, 'created' => DateTimeFormat::utcNow(),
|
||||
'last_failure' => DateTimeFormat::utcNow()]);
|
||||
'failed' => true, 'last_failure' => DateTimeFormat::utcNow()]);
|
||||
Logger::info('Set failed status for new server', ['url' => $url]);
|
||||
}
|
||||
|
||||
|
@ -303,7 +303,8 @@ class GServer
|
|||
|
||||
// If the URL missmatches, then we mark the old entry as failure
|
||||
if ($url != $original_url) {
|
||||
DBA::update('gserver', ['last_failure' => DateTimeFormat::utcNow()], ['nurl' => Strings::normaliseLink($original_url)]);
|
||||
DBA::update('gserver', ['failed' => true, 'last_failure' => DateTimeFormat::utcNow()],
|
||||
['nurl' => Strings::normaliseLink($original_url)]);
|
||||
}
|
||||
|
||||
// When a nodeinfo is present, we don't need to dig further
|
||||
|
@ -449,6 +450,7 @@ class GServer
|
|||
}
|
||||
|
||||
$serverdata['last_contact'] = DateTimeFormat::utcNow();
|
||||
$serverdata['failed'] = false;
|
||||
|
||||
$gserver = DBA::selectFirst('gserver', ['network'], ['nurl' => Strings::normaliseLink($url)]);
|
||||
if (!DBA::isResult($gserver)) {
|
||||
|
@ -1585,7 +1587,7 @@ class GServer
|
|||
|
||||
$gservers = DBA::p("SELECT `id`, `url`, `nurl`, `network`, `poco`
|
||||
FROM `gserver`
|
||||
WHERE `last_contact` >= `last_failure`
|
||||
WHERE NOT `failed`
|
||||
AND `poco` != ''
|
||||
AND `last_poco_query` < ?
|
||||
ORDER BY RAND()", $last_update
|
||||
|
|
|
@ -2415,7 +2415,7 @@ class Item
|
|||
}
|
||||
|
||||
/// @todo On private posts we could obfuscate the date
|
||||
$update = ($arr['private'] != self::PRIVATE);
|
||||
$update = ($arr['private'] != self::PRIVATE) || in_array($arr['network'], Protocol::FEDERATED);
|
||||
|
||||
// Is it a forum? Then we don't care about the rules from above
|
||||
if (!$update && in_array($arr["network"], [Protocol::ACTIVITYPUB, Protocol::DFRN]) && ($arr["parent-uri"] === $arr["uri"])) {
|
||||
|
@ -2433,15 +2433,15 @@ class Item
|
|||
} else {
|
||||
$condition = ['id' => $arr['contact-id'], 'self' => false];
|
||||
}
|
||||
DBA::update('contact', ['success_update' => $arr['received'], 'last-item' => $arr['received']], $condition);
|
||||
DBA::update('contact', ['failed' => false, 'success_update' => $arr['received'], 'last-item' => $arr['received']], $condition);
|
||||
}
|
||||
// Now do the same for the system wide contacts with uid=0
|
||||
if ($arr['private'] != self::PRIVATE) {
|
||||
DBA::update('contact', ['success_update' => $arr['received'], 'last-item' => $arr['received']],
|
||||
DBA::update('contact', ['failed' => false, 'success_update' => $arr['received'], 'last-item' => $arr['received']],
|
||||
['id' => $arr['owner-id']]);
|
||||
|
||||
if ($arr['owner-id'] != $arr['author-id']) {
|
||||
DBA::update('contact', ['success_update' => $arr['received'], 'last-item' => $arr['received']],
|
||||
DBA::update('contact', ['failed' => false, 'success_update' => $arr['received'], 'last-item' => $arr['received']],
|
||||
['id' => $arr['author-id']]);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue