Skip to content

Commit

Permalink
[histories] order by date, id
Browse files Browse the repository at this point in the history
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
  • Loading branch information
discomrade authored and shish committed Sep 7, 2024
1 parent 9354725 commit 505d08a
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 7 deletions.
10 changes: 5 additions & 5 deletions ext/notes/main.php
Original file line number Diff line number Diff line change
Expand Up @@ -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]);
}

Expand Down Expand Up @@ -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]
);

Expand All @@ -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]
);

Expand Down Expand Up @@ -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]
);

Expand All @@ -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]
);

Expand Down
2 changes: 1 addition & 1 deletion ext/source_history/main.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)) {
Expand Down
2 changes: 1 addition & 1 deletion ext/tag_history/main.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)) {
Expand Down

0 comments on commit 505d08a

Please sign in to comment.