Leave the image data out of the story lists.

A page of 50 stories read 50 images from the database only to see which stories had one.
This commit is contained in:
tim
2026-09-26 15:27:51 +02:00
parent ed8918e7fd
commit c8030b759d
4 changed files with 41 additions and 12 deletions
+11 -4
View File
@@ -150,6 +150,13 @@ function get_count() {
return $row_count[0];
}
/*
* The story columns that the pages read. The image data stays in the
* database (display.php reads it): img is 1 for a story with an image,
* and NULL for one without.
*/
define('STORY_COLUMNS', 'id, title, author, email, date, story, hidden, mime, comments, editor, IF(LENGTH(img) > 0, 1, NULL) AS img');
/*
* Return array of results, correctly keyed to column names.
*/
@@ -169,13 +176,13 @@ function get_query($id = NULL) {
// If id= is defined, show the corresponding application only
if (is_numeric($id)) {
if (!$is_admin)
$query = "SELECT * FROM $table WHERE 1 AND hidden IS NOT TRUE AND id = ".(int)$id." LIMIT 0, 1";
$query = "SELECT ".STORY_COLUMNS." FROM $table WHERE 1 AND hidden IS NOT TRUE AND id = ".(int)$id." LIMIT 0, 1";
else
$query = "SELECT * FROM $table WHERE 1 AND id = ".(int)$id." LIMIT 0, 1";
$query = "SELECT ".STORY_COLUMNS." FROM $table WHERE 1 AND id = ".(int)$id." LIMIT 0, 1";
// if search= is defined, search....
} else if ($search) {
$query = "SELECT * FROM $table WHERE".
$query = "SELECT ".STORY_COLUMNS." FROM $table WHERE".
" (title LIKE ? OR author LIKE ? OR date LIKE ? OR story LIKE ?)";
$params = array_fill(0, 4, "%$search%");
if (!$is_admin)
@@ -183,7 +190,7 @@ function get_query($id = NULL) {
$query .= " ORDER BY ".$sort." ".$order.$limit;
// Otherwise, fall back to default view
} else {
$query = "SELECT * FROM ".$table." WHERE 1";
$query = "SELECT ".STORY_COLUMNS." FROM ".$table." WHERE 1";
if (!$is_admin)
$query .= " AND hidden IS NOT TRUE";
$query .= " ORDER BY ".$sort." ".$order.$limit;