Fix homepage building

- fix sql query that returned rows without files, the only
reason the size summation function worked was because php regexes used
to allow a null argument. Now returns less rows and only those with
files (original sql was semantically wrong)
This commit is contained in:
towards-a-new-leftypol 2023-08-03 17:30:05 -04:00
parent e7de262d71
commit 151c64110d
1 changed files with 5 additions and 4 deletions

View File

@ -138,12 +138,13 @@
foreach ($boards as &$_board) { foreach ($boards as &$_board) {
if (in_array($_board['uri'], $this->excluded)) if (in_array($_board['uri'], $this->excluded))
continue; continue;
$query .= sprintf("SELECT `files` FROM ``posts_%s`` UNION ALL ", $_board['uri']); $query .= sprintf("SELECT `files` FROM `posts_%s` WHERE `num_files` > 0 UNION ALL ", $_board['uri']);
} }
$query = preg_replace('/UNION ALL $/', ' WHERE `num_files` > 0) AS `posts_all`', $query); $query = preg_replace('/UNION ALL $/', ') AS `posts_all`', $query);
$query = query($query) or error(db_error()); $query = query($query) or error(db_error());
$files = $query->fetchAll(); $files = $query->fetchAll();
$stats['active_content'] = 0; $stats['active_content'] = 0;
foreach ($files as &$file) { foreach ($files as &$file) {
preg_match_all('/"size":([0-9]*)/', $file[0], $matches); preg_match_all('/"size":([0-9]*)/', $file[0], $matches);
$stats['active_content'] += array_sum($matches[1]); $stats['active_content'] += array_sum($matches[1]);