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

View file

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

View file

@ -95,7 +95,7 @@ class GContact
$results = DBA::p("SELECT `nurl` FROM `gcontact` $results = DBA::p("SELECT `nurl` FROM `gcontact`
WHERE NOT `hide` AND `network` IN (?, ?, ?, ?) AND 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 (`addr` LIKE ? OR `name` LIKE ? OR `nick` LIKE ?) $extra_sql
GROUP BY `nurl` ORDER BY `nurl` DESC LIMIT 1000", GROUP BY `nurl` ORDER BY `nurl` DESC LIMIT 1000",
Protocol::DFRN, Protocol::ACTIVITYPUB, $ostatus, $diaspora, $search, $search, $search Protocol::DFRN, Protocol::ACTIVITYPUB, $ostatus, $diaspora, $search, $search, $search
@ -274,8 +274,7 @@ class GContact
"SELECT count(*) as `total` "SELECT count(*) as `total`
FROM `glink` INNER JOIN `gcontact` on `glink`.`gcid` = `gcontact`.`id` FROM `glink` INNER JOIN `gcontact` on `glink`.`gcid` = `gcontact`.`id`
WHERE `glink`.`cid` = %d AND `glink`.`uid` = %d AND WHERE `glink`.`cid` = %d AND `glink`.`uid` = %d AND
((`gcontact`.`last_contact` >= `gcontact`.`last_failure`) OR NOT `gcontact`.`failed`
(`gcontact`.`updated` >= `gcontact`.`last_failure`))
AND `gcontact`.`nurl` IN (select nurl from contact where uid = %d and self = 0 and blocked = 0 and hidden = 0 and id != %d) ", 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($cid),
intval($uid), intval($uid),
@ -338,7 +337,7 @@ class GContact
WHERE `glink`.`cid` = %d and `glink`.`uid` = %d WHERE `glink`.`cid` = %d and `glink`.`uid` = %d
AND `contact`.`uid` = %d AND `contact`.`self` = 0 AND `contact`.`blocked` = 0 AND `contact`.`uid` = %d AND `contact`.`self` = 0 AND `contact`.`blocked` = 0
AND `contact`.`hidden` = 0 AND `contact`.`id` != %d 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", $sql_extra LIMIT %d, %d",
intval($cid), intval($cid),
intval($uid), intval($uid),
@ -397,7 +396,7 @@ class GContact
"SELECT count(*) as `total` "SELECT count(*) as `total`
FROM `glink` INNER JOIN `gcontact` on `glink`.`gcid` = `gcontact`.`id` FROM `glink` INNER JOIN `gcontact` on `glink`.`gcid` = `gcontact`.`id`
where `glink`.`cid` = %d and `glink`.`uid` = %d AND 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($cid),
intval($uid) intval($uid)
); );
@ -425,7 +424,7 @@ class GContact
INNER JOIN `gcontact` on `glink`.`gcid` = `gcontact`.`id` INNER JOIN `gcontact` on `glink`.`gcid` = `gcontact`.`id`
LEFT JOIN `contact` ON `contact`.`nurl` = `gcontact`.`nurl` AND `contact`.`uid` = %d LEFT JOIN `contact` ON `contact`.`nurl` = `gcontact`.`nurl` AND `contact`.`uid` = %d
WHERE `glink`.`cid` = %d AND `glink`.`uid` = %d AND 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 ", ORDER BY `gcontact`.`name` ASC LIMIT %d, %d ",
intval($uid), intval($uid),
intval($cid), intval($cid),
@ -472,7 +471,7 @@ class GContact
AND NOT `gcontact`.`name` IN (SELECT `name` FROM `contact` WHERE `uid` = %d) 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 NOT `gcontact`.`id` IN (SELECT `gcid` FROM `gcign` WHERE `uid` = %d)
AND `gcontact`.`updated` >= '%s' AND NOT `gcontact`.`hide` AND `gcontact`.`updated` >= '%s' AND NOT `gcontact`.`hide`
AND `gcontact`.`last_contact` >= `gcontact`.`last_failure` AND NOT `gcontact`.`failed`
AND `gcontact`.`network` IN (%s) AND `gcontact`.`network` IN (%s)
GROUP BY `glink`.`gcid` ORDER BY `gcontact`.`updated` DESC,`total` DESC LIMIT %d, %d", GROUP BY `glink`.`gcid` ORDER BY `gcontact`.`updated` DESC,`total` DESC LIMIT %d, %d",
intval($uid), intval($uid),
@ -496,7 +495,7 @@ class GContact
AND NOT `gcontact`.`name` IN (SELECT `name` FROM `contact` WHERE `uid` = %d) 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 NOT `gcontact`.`id` IN (SELECT `gcid` FROM `gcign` WHERE `uid` = %d)
AND `gcontact`.`updated` >= '%s' AND `gcontact`.`updated` >= '%s'
AND `gcontact`.`last_contact` >= `gcontact`.`last_failure` AND NOT `gcontact`.`failed`
AND `gcontact`.`network` IN (%s) AND `gcontact`.`network` IN (%s)
ORDER BY rand() LIMIT %d, %d", ORDER BY rand() LIMIT %d, %d",
intval($uid), intval($uid),
@ -1270,7 +1269,7 @@ class GContact
$r = DBA::select('gserver', ['nurl', 'url'], [ $r = DBA::select('gserver', ['nurl', 'url'], [
'`network` = ? '`network` = ?
AND `last_contact` >= `last_failure` AND NOT `failed`
AND `last_poco_query` < ?', AND `last_poco_query` < ?',
Protocol::OSTATUS, Protocol::OSTATUS,
$last_update $last_update
@ -1422,7 +1421,7 @@ class GContact
{ {
$r = DBA::selectFirst('gcontact', ['url'], [ $r = DBA::selectFirst('gcontact', ['url'], [
'`network` = ? '`network` = ?
AND `last_contact` >= `last_failure` AND NOT `failed`
AND `updated` > ?', AND `updated` > ?',
Protocol::DFRN, Protocol::DFRN,
DateTimeFormat::utc('now - 1 month'), DateTimeFormat::utc('now - 1 month'),

View file

@ -1587,7 +1587,7 @@ class GServer
$gservers = DBA::p("SELECT `id`, `url`, `nurl`, `network`, `poco` $gservers = DBA::p("SELECT `id`, `url`, `nurl`, `network`, `poco`
FROM `gserver` FROM `gserver`
WHERE `last_contact` >= `last_failure` WHERE NOT `failed`
AND `poco` != '' AND `poco` != ''
AND `last_poco_query` < ? AND `last_poco_query` < ?
ORDER BY RAND()", $last_update 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`, $gservers = DBA::p("SELECT COUNT(*) AS `total`, SUM(`registered-users`) AS `users`, `platform`,
ANY_VALUE(`network`) AS `network`, MAX(`version`) AS `version` 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)) { while ($gserver = DBA::fetch($gservers)) {
$total += $gserver['total']; $total += $gserver['total'];
$users += $gserver['users']; $users += $gserver['users'];
$versionCounts = []; $versionCounts = [];
$versions = DBA::p("SELECT COUNT(*) AS `total`, `version` FROM `gserver` $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']); GROUP BY `version` ORDER BY `version`", $gserver['platform']);
while ($version = DBA::fetch($versions)) { while ($version = DBA::fetch($versions)) {
$version['version'] = str_replace(["\n", "\r", "\t"], " ", $version['version']); $version['version'] = str_replace(["\n", "\r", "\t"], " ", $version['version']);

View file

@ -42,7 +42,7 @@ class Peers extends BaseApi
$return = []; $return = [];
// We only select for Friendica and ActivityPub servers, since it is expected to only deliver AP compatible systems here. // 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)) { while ($instance = DBA::fetch($instances)) {
$urldata = parse_url($instance['url']); $urldata = parse_url($instance['url']);
unset($urldata['scheme']); unset($urldata['scheme']);

View file

@ -51,7 +51,7 @@ class Stats extends BaseEntity
if (!empty(DI::config()->get('system', 'nodeinfo'))) { if (!empty(DI::config()->get('system', 'nodeinfo'))) {
$stats->user_count = intval(DI::config()->get('nodeinfo', 'total_users')); $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->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; return $stats;
} }

View file

@ -228,7 +228,7 @@ class PortableContact
{ {
$r = q( $r = q(
"SELECT `url`, `site_name` AS `displayName`, `network`, `platform`, `version` FROM `gserver` "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` ORDER BY `last_contact`
LIMIT 1000", LIMIT 1000",
DBA::escape(Protocol::DFRN), DBA::escape(Protocol::DFRN),

View file

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