Use "failed" field

This commit is contained in:
Michael 2020-07-19 11:42:23 +00:00
parent ebcf757244
commit 5bf813d0ec
9 changed files with 22 additions and 24 deletions

View file

@ -110,7 +110,7 @@ function poco_init(App $a) {
$totalResults = DBA::count('profile', ['net-publish' => true]);
} else {
$contacts = q("SELECT count(*) AS `total` FROM `contact` WHERE `uid` = %d AND `blocked` = 0 AND `pending` = 0 AND `hidden` = 0 AND `archive` = 0
AND (`success_update` >= `failure_update` OR `last-item` >= `failure_update`)
AND NOT `failed`
AND `network` IN ('%s', '%s', '%s', '%s') $sql_extra",
intval($user['uid']),
DBA::escape(Protocol::DFRN),
@ -148,7 +148,7 @@ function poco_init(App $a) {
} else {
Logger::log("Start query for user " . $user['nickname'], Logger::DEBUG);
$contacts = q("SELECT * FROM `contact` WHERE `uid` = %d AND `blocked` = 0 AND `pending` = 0 AND `hidden` = 0 AND `archive` = 0
AND (`success_update` >= `failure_update` OR `last-item` >= `failure_update`)
AND NOT `failed`
AND `network` IN ('%s', '%s', '%s', '%s') $sql_extra LIMIT %d, %d",
intval($user['uid']),
DBA::escape(Protocol::DFRN),

View file

@ -180,7 +180,7 @@ class Search
$count = DBA::count('gcontact', [
'NOT `hide`
AND `network` IN (?, ?, ?, ?)
AND ((`last_contact` >= `last_failure`) OR (`updated` >= `last_failure`))
AND NOT `failed`
AND (`url` LIKE ? OR `name` LIKE ? OR `location` LIKE ?
OR `addr` LIKE ? OR `about` LIKE ? OR `keywords` LIKE ?)
AND `community` = ?',
@ -199,7 +199,7 @@ class Search
$data = DBA::select('gcontact', ['nurl', 'name', 'addr', 'url', 'photo', 'network', 'keywords'], [
'NOT `hide`
AND `network` IN (?, ?, ?, ?)
AND ((`last_contact` >= `last_failure`) OR (`updated` >= `last_failure`))
AND NOT `failed`
AND (`url` LIKE ? OR `name` LIKE ? OR `location` LIKE ?
OR `addr` LIKE ? OR `about` LIKE ? OR `keywords` LIKE ?)
AND `community` = ?',

View file

@ -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
@ -274,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),
@ -338,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),
@ -397,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)
);
@ -425,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),
@ -472,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),
@ -496,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),
@ -1270,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
@ -1421,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'),

View file

@ -1587,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

View file

@ -64,14 +64,14 @@ class Federation extends BaseAdmin
$gservers = DBA::p("SELECT COUNT(*) AS `total`, SUM(`registered-users`) AS `users`, `platform`,
ANY_VALUE(`network`) AS `network`, MAX(`version`) AS `version`
FROM `gserver` WHERE `last_contact` >= `last_failure` GROUP BY `platform`");
FROM `gserver` WHERE NOT `failed` GROUP BY `platform`");
while ($gserver = DBA::fetch($gservers)) {
$total += $gserver['total'];
$users += $gserver['users'];
$versionCounts = [];
$versions = DBA::p("SELECT COUNT(*) AS `total`, `version` FROM `gserver`
WHERE `last_contact` >= `last_failure` AND `platform` = ?
WHERE NOT `failed` AND `platform` = ?
GROUP BY `version` ORDER BY `version`", $gserver['platform']);
while ($version = DBA::fetch($versions)) {
$version['version'] = str_replace(["\n", "\r", "\t"], " ", $version['version']);

View file

@ -42,7 +42,7 @@ class Peers extends BaseApi
$return = [];
// We only select for Friendica and ActivityPub servers, since it is expected to only deliver AP compatible systems here.
$instances = DBA::select('gserver', ['url'], ["`network` in (?, ?) AND `last_contact` >= `last_failure`", Protocol::DFRN, Protocol::ACTIVITYPUB]);
$instances = DBA::select('gserver', ['url'], ["`network` in (?, ?) AND NOT `failed`", Protocol::DFRN, Protocol::ACTIVITYPUB]);
while ($instance = DBA::fetch($instances)) {
$urldata = parse_url($instance['url']);
unset($urldata['scheme']);

View file

@ -51,7 +51,7 @@ class Stats extends BaseEntity
if (!empty(DI::config()->get('system', 'nodeinfo'))) {
$stats->user_count = intval(DI::config()->get('nodeinfo', 'total_users'));
$stats->status_count = DI::config()->get('nodeinfo', 'local_posts') + DI::config()->get('nodeinfo', 'local_comments');
$stats->domain_count = DBA::count('gserver', ["`network` in (?, ?) AND `last_contact` >= `last_failure`", Protocol::DFRN, Protocol::ACTIVITYPUB]);
$stats->domain_count = DBA::count('gserver', ["`network` in (?, ?) AND NOT `failed`", Protocol::DFRN, Protocol::ACTIVITYPUB]);
}
return $stats;
}

View file

@ -228,7 +228,7 @@ class PortableContact
{
$r = q(
"SELECT `url`, `site_name` AS `displayName`, `network`, `platform`, `version` FROM `gserver`
WHERE `network` IN ('%s', '%s', '%s') AND `last_contact` > `last_failure`
WHERE `network` IN ('%s', '%s', '%s') AND NOT `failed`
ORDER BY `last_contact`
LIMIT 1000",
DBA::escape(Protocol::DFRN),

View file

@ -58,12 +58,11 @@ class SearchDirectory
if (!empty($j->results)) {
foreach ($j->results as $jj) {
// Check if the contact already exists
$gcontact = DBA::selectFirst('gcontact', ['id', 'last_contact', 'last_failure', 'updated'], ['nurl' => Strings::normaliseLink($jj->url)]);
$gcontact = DBA::selectFirst('gcontact', ['failed'], ['nurl' => Strings::normaliseLink($jj->url)]);
if (DBA::isResult($gcontact)) {
Logger::info('Profile already exists', ['profile' => $jj->url, 'search' => $search]);
if (($gcontact['last_contact'] < $gcontact['last_failure']) &&
($gcontact['updated'] < $gcontact['last_failure'])) {
if ($gcontact['failed']) {
continue;
}