[DATABASE] Fix use of ORDER BY with DISTINCT
statuses/retweets_of_me has performance fixed, so it is also stripped of its "bad query" status.
This commit is contained in:
@@ -52,32 +52,32 @@ if (!($broken ^ $h_bug)) {
|
||||
die();
|
||||
}
|
||||
|
||||
$query = "
|
||||
SELECT DISTINCT
|
||||
file_to_post.file_id
|
||||
FROM
|
||||
file_to_post
|
||||
INNER JOIN
|
||||
file ON file.id = file_to_post.file_id
|
||||
INNER JOIN
|
||||
notice ON notice.id = file_to_post.post_id
|
||||
WHERE";
|
||||
$fn = new DB_DataObject();
|
||||
|
||||
$query = <<<'END'
|
||||
SELECT file_to_post.file_id
|
||||
FROM file_to_post
|
||||
INNER JOIN file ON file_to_post.file_id = file.id
|
||||
INNER JOIN notice ON file_to_post.post_id = notice.id
|
||||
WHERE
|
||||
END;
|
||||
|
||||
$f = new File();
|
||||
if ($h_bug) {
|
||||
$query .= " file.title = 'h'
|
||||
AND file.mimetype = 'h'
|
||||
AND file.size = 0
|
||||
AND file.protected = 0";
|
||||
$query .= <<<'END'
|
||||
file.title = 'h'
|
||||
AND file.mimetype = 'h'
|
||||
AND file.size = 0
|
||||
AND file.protected = 0
|
||||
END;
|
||||
} elseif ($broken) {
|
||||
$query .= " file.filename is NULL";
|
||||
$query .= ' file.filename IS NULL';
|
||||
}
|
||||
|
||||
$query .= empty($limit) ? "" : " AND notice.modified >= '{$limit}' ORDER BY notice.modified ASC";
|
||||
if (!empty($limit)) {
|
||||
$query .= " AND notice.modified >= '{$fn->escape($limit)}'";
|
||||
}
|
||||
$query .= ' GROUP BY file_to_post.file_id ORDER BY MAX(notice.modified)';
|
||||
|
||||
// echo $query;
|
||||
|
||||
$fn = new DB_DataObject();
|
||||
$fn->query($query);
|
||||
|
||||
if ($h_bug) {
|
||||
@@ -133,14 +133,15 @@ while ($fn->fetch()) {
|
||||
echo " (ok, but embedding lookup failed)\n";
|
||||
}
|
||||
}
|
||||
} elseif ($broken &&
|
||||
(!$data instanceof File_embed ||
|
||||
empty($data->title) ||
|
||||
empty($f->title)
|
||||
||
|
||||
($thumb instanceof File_thumbnail && empty($thumb->filename))
|
||||
)) {
|
||||
|
||||
} elseif (
|
||||
$broken
|
||||
&& (
|
||||
!($data instanceof File_embed)
|
||||
|| empty($data->title)
|
||||
|| empty($f->title)
|
||||
|| ($thumb instanceof File_thumbnail && empty($thumb->filename))
|
||||
)
|
||||
) {
|
||||
// print_r($thumb);
|
||||
|
||||
if (!$dry) {
|
||||
|
@@ -59,25 +59,23 @@ if (empty($max_date)) {
|
||||
exit(1);
|
||||
}
|
||||
|
||||
$query = "
|
||||
SELECT DISTINCT
|
||||
file_to_post.file_id
|
||||
FROM
|
||||
file_to_post
|
||||
INNER JOIN
|
||||
file ON file.id = file_to_post.file_id
|
||||
INNER JOIN
|
||||
notice ON notice.id = file_to_post.post_id
|
||||
WHERE
|
||||
notice.is_local = 0 ";
|
||||
|
||||
$query .= $image_only ? " AND file.width IS NOT NULL AND file.height IS NOT NULL " : "";
|
||||
|
||||
$query .= $include_previews ? "" : " AND file.filehash IS NOT NULL ";
|
||||
$query .= " AND notice.modified <= '{$max_date}' ORDER BY notice.modified ASC";
|
||||
|
||||
$fn = new DB_DataObject();
|
||||
$fn->query($query);
|
||||
$fn->query(sprintf(
|
||||
<<<'END'
|
||||
SELECT file_to_post.file_id
|
||||
FROM file_to_post
|
||||
INNER JOIN file ON file_to_post.file_id = file.id
|
||||
INNER JOIN notice ON file_to_post.post_id = notice.id
|
||||
WHERE notice.is_local = 0
|
||||
%1$s%2$sAND notice.modified <= '%3$s'
|
||||
GROUP BY file_to_post.file_id
|
||||
ORDER BY MAX(notice.modified)
|
||||
END,
|
||||
$image_only ? 'AND file.width IS NOT NULL AND file.height IS NOT NULL ' : '',
|
||||
$include_previews ? '' : 'AND file.filehash IS NOT NULL ',
|
||||
$fn->escape($max_date)
|
||||
));
|
||||
|
||||
while ($fn->fetch()) {
|
||||
$file = File::getByID($fn->file_id);
|
||||
$file_info_id = $file->getID();
|
||||
|
Reference in New Issue
Block a user