minor refactor

This commit is contained in:
Gerrit Uitslag 2023-09-25 21:01:19 +02:00
parent adf3f0ade0
commit 9349c09b46
1 changed files with 11 additions and 8 deletions

View File

@ -174,8 +174,9 @@ function getRecents($first, $num, $ns = '', $flags = 0)
$recent = [];
$count = 0;
if (!$num)
if (!$num) {
return $recent;
}
// read all recent changes. (kept short)
if ($flags & RECENTS_MEDIA_CHANGES) {
@ -198,19 +199,19 @@ function getRecents($first, $num, $ns = '', $flags = 0)
$media_lines_position = count($media_lines) - 1;
}
$seen = []; // caches seen lines, _handleRecent() skips them
$seen = []; // caches seen lines, _handleRecentLogLine() skips them
// handle lines
while ($lines_position >= 0 || (($flags & RECENTS_MEDIA_PAGES_MIXED) && $media_lines_position >= 0)) {
if (empty($rec) && $lines_position >= 0) {
$rec = _handleRecent(@$lines[$lines_position], $ns, $flags, $seen);
$rec = _handleRecentLogLine(@$lines[$lines_position], $ns, $flags, $seen);
if (!$rec) {
$lines_position--;
continue;
}
}
if (($flags & RECENTS_MEDIA_PAGES_MIXED) && empty($media_rec) && $media_lines_position >= 0) {
$media_rec = _handleRecent(
$media_rec = _handleRecentLogLine(
@$media_lines[$media_lines_position],
$ns,
$flags | RECENTS_MEDIA_CHANGES,
@ -274,8 +275,9 @@ function getRecentsSince($from, $to = null, $ns = '', $flags = 0)
global $conf;
$recent = [];
if ($to && $to < $from)
if ($to && $to < $from) {
return $recent;
}
// read all recent changes. (kept short)
if ($flags & RECENTS_MEDIA_CHANGES) {
@ -289,10 +291,10 @@ function getRecentsSince($from, $to = null, $ns = '', $flags = 0)
$lines = array_reverse($lines);
// handle lines
$seen = []; // caches seen lines, _handleRecent() skips them
$seen = []; // caches seen lines, _handleRecentLogLine() skips them
foreach ($lines as $line) {
$rec = _handleRecent($line, $ns, $flags, $seen);
$rec = _handleRecentLogLine($line, $ns, $flags, $seen);
if ($rec !== false) {
if ($rec['date'] >= $from) {
if (!$to || $rec['date'] <= $to) {
@ -309,6 +311,7 @@ function getRecentsSince($from, $to = null, $ns = '', $flags = 0)
/**
* Internal function used by getRecents
* Parse a line and checks whether it should be included
*
* don't call directly
*
@ -322,7 +325,7 @@ function getRecentsSince($from, $to = null, $ns = '', $flags = 0)
* @param array $seen listing of seen pages
* @return array|bool false or array with info about a change
*/
function _handleRecent($line, $ns, $flags, &$seen)
function _handleRecentLogLine($line, $ns, $flags, &$seen)
{
if (empty($line)) return false; //skip empty lines