New rating scale

This commit is contained in:
Michael 2020-08-17 06:47:29 +00:00
parent 975bb76291
commit 7370a075f8
2 changed files with 62 additions and 18 deletions

View File

@ -693,16 +693,23 @@ class Feed
$max = $ppd;
}
}
if ($max >= 24) {
$priority = 0; // Poll with the minimum poll intervall
} elseif ($max >= 12) {
$priority = 1; // Poll hourly
if ($max > 48) {
$priority = 1; // Poll every quarter hour
} elseif ($max > 24) {
$priority = 2; // Poll half an hour
} elseif ($max > 12) {
$priority = 3; // Poll hourly
} elseif ($max > 8) {
$priority = 4; // Poll every two hours
} elseif ($max > 4) {
$priority = 5; // Poll every three hours
} elseif ($max > 2) {
$priority = 6; // Poll every six hours
} elseif ($max > 1) {
$priority = 2; // Poll twice a day
$priority = 7; // Poll twice a day
} else {
/// @todo In the future we could calculate the days between the posts to set even lower priorities
$priority = 3; // Poll once a day
$priority = 8; // Poll once a day
}
Logger::info('Calculated priority by the posts per day', ['priority' => $priority, 'max' => round($max, 2), 'id' => $contact['id'], 'uid' => $contact['uid'], 'url' => $contact['url']]);
}

View File

@ -219,25 +219,37 @@ class Cron
while ($contact = DBA::fetch($contacts)) {
// Use the "rating" field when auto adjusting the poll intervall
if (DI::config()->get('system', 'adjust_poll_frequency') && ($contact['network'] == Protocol::FEED)) {
$contact['priority'] = max($contact['rating'], $contact['priority']);
$rating = $contact['rating'];
} elseif ($contact['priority'] == 1) {
$rating = 3;
} elseif ($contact['priority'] == 2) {
$rating = 7;
} elseif ($contact['priority'] == 3) {
$rating = 8;
} elseif ($contact['priority'] == 4) {
$rating = 9;
} elseif ($contact['priority'] == 5) {
$rating = 10;
} else {
$rating = -1;
}
// Friendica and OStatus are checked once a day
if (in_array($contact['network'], [Protocol::DFRN, Protocol::OSTATUS])) {
$contact['priority'] = 3;
$rating = 8;
}
// ActivityPub is checked once a week
if ($contact['network'] == Protocol::ACTIVITYPUB) {
$contact['priority'] = 4;
$rating = 9;
}
// Check archived contacts once a month
if ($contact['archive']) {
$contact['priority'] = 5;
$rating = 10;
}
if ($contact['priority'] >= 0) {
if ($rating >= 0) {
$update = false;
$t = $contact['last-update'];
@ -245,32 +257,57 @@ class Cron
/*
* Based on $contact['priority'], should we poll this site now? Or later?
*/
switch ($contact['priority']) {
case 5:
switch ($rating) {
case 10:
if (DateTimeFormat::utcNow() > DateTimeFormat::utc($t . " + 1 month")) {
$update = true;
}
break;
case 4:
case 9:
if (DateTimeFormat::utcNow() > DateTimeFormat::utc($t . " + 1 week")) {
$update = true;
}
break;
case 3:
case 8:
if (DateTimeFormat::utcNow() > DateTimeFormat::utc($t . " + 1 day")) {
$update = true;
}
break;
case 2:
case 7:
if (DateTimeFormat::utcNow() > DateTimeFormat::utc($t . " + 12 hour")) {
$update = true;
}
break;
case 1:
case 6:
if (DateTimeFormat::utcNow() > DateTimeFormat::utc($t . " + 6 hour")) {
$update = true;
}
break;
case 5:
if (DateTimeFormat::utcNow() > DateTimeFormat::utc($t . " + 3 hour")) {
$update = true;
}
break;
case 4:
if (DateTimeFormat::utcNow() > DateTimeFormat::utc($t . " + 2 hour")) {
$update = true;
}
break;
case 3:
if (DateTimeFormat::utcNow() > DateTimeFormat::utc($t . " + 1 hour")) {
$update = true;
}
break;
case 2:
if (DateTimeFormat::utcNow() > DateTimeFormat::utc($t . " + 30 minute")) {
$update = true;
}
break;
case 1:
if (DateTimeFormat::utcNow() > DateTimeFormat::utc($t . " + 15 minute")) {
$update = true;
}
break;
case 0:
default:
if (DateTimeFormat::utcNow() > DateTimeFormat::utc($t . " + " . $min_poll_interval . " minute")) {