From 505d08a10f2f36800859bd0eb47396440313b5b1 Mon Sep 17 00:00:00 2001 From: discomrade <83621080+discomrade@users.noreply.github.com> Date: Fri, 26 Apr 2024 08:35:38 +0000 Subject: [PATCH] [histories] order by date, id Sort tag histories, source histories and notes by id after date. Date is not necessarily unique, such as two simultaneous posts or migrating from a booru software which doesn't store the dates correctly --- ext/notes/main.php | 10 +++++----- ext/source_history/main.php | 2 +- ext/tag_history/main.php | 2 +- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/ext/notes/main.php b/ext/notes/main.php index 0028d7719..2a9fa98e2 100644 --- a/ext/notes/main.php +++ b/ext/notes/main.php @@ -233,7 +233,7 @@ private function get_notes(int $imageID): array SELECT * FROM notes WHERE enable = :enable AND image_id = :image_id - ORDER BY date ASC + ORDER BY date ASC, id ASC ", ['enable' => '1', 'image_id' => $imageID]); } @@ -363,7 +363,7 @@ private function get_notes_list(int $pageNumber): void SELECT DISTINCT image_id FROM notes WHERE enable = :enable - ORDER BY date DESC LIMIT :limit OFFSET :offset", + ORDER BY date DESC, id DESC LIMIT :limit OFFSET :offset", ['enable' => 1, 'offset' => $pageNumber * $notesPerPage, 'limit' => $notesPerPage] ); @@ -387,7 +387,7 @@ private function get_notes_requests(int $pageNumber): void " SELECT DISTINCT image_id FROM note_request - ORDER BY date DESC LIMIT :limit OFFSET :offset", + ORDER BY date DESC, id DESC LIMIT :limit OFFSET :offset", ["offset" => $pageNumber * $requestsPerPage, "limit" => $requestsPerPage] ); @@ -441,7 +441,7 @@ private function get_histories(int $pageNumber): void "FROM note_histories AS h " . "INNER JOIN users AS u " . "ON u.id = h.user_id " . - "ORDER BY date DESC LIMIT :limit OFFSET :offset", + "ORDER BY date DESC, note_id DESC LIMIT :limit OFFSET :offset", ['offset' => $pageNumber * $historiesPerPage, 'limit' => $historiesPerPage] ); @@ -462,7 +462,7 @@ private function get_history(int $noteID, int $pageNumber): void "INNER JOIN users AS u " . "ON u.id = h.user_id " . "WHERE note_id = :note_id " . - "ORDER BY date DESC LIMIT :limit OFFSET :offset", + "ORDER BY date DESC, note_id DESC LIMIT :limit OFFSET :offset", ['note_id' => $noteID, 'offset' => $pageNumber * $historiesPerPage, 'limit' => $historiesPerPage] ); diff --git a/ext/source_history/main.php b/ext/source_history/main.php index aa2547264..921ee95ee 100644 --- a/ext/source_history/main.php +++ b/ext/source_history/main.php @@ -305,7 +305,7 @@ public function process_revert_all_changes(?string $name, ?string $ip, ?string $ FROM source_histories WHERE image_id='.$image_id.' AND NOT ('.implode(" AND ", $select_code).') - ORDER BY date_set DESC LIMIT 1 + ORDER BY date_set DESC, id DESC LIMIT 1 ', $select_args); if (!empty($row)) { diff --git a/ext/tag_history/main.php b/ext/tag_history/main.php index cf8d3e420..b63849208 100644 --- a/ext/tag_history/main.php +++ b/ext/tag_history/main.php @@ -367,7 +367,7 @@ public function process_revert_all_changes(?string $name, ?string $ip, ?string $ FROM tag_histories WHERE image_id='.$image_id.' AND NOT ('.implode(" AND ", $select_code).') - ORDER BY date_set DESC LIMIT 1 + ORDER BY date_set DESC, id DESC LIMIT 1 ', $select_args); if (!empty($row)) {