Sort emojis by updatedAt
ci/woodpecker/tag/ociImageTag Pipeline was successful Details

This commit is contained in:
Natty 2024-01-01 22:07:40 +01:00
parent 96c748f807
commit eab77d9225
Signed by: natty
GPG Key ID: BF6CB659ADEE60EC
2 changed files with 17 additions and 11 deletions

View File

@ -6,7 +6,10 @@ export function makePaginationQuery<T>(
untilId?: string,
sinceDate?: number,
untilDate?: number,
timeColumn?: string
) {
timeColumn = timeColumn ?? "createdAt";
if (!sinceDate && !untilDate && (sinceId || untilId)) {
if (sinceId && untilId) {
q.andWhere(`${q.alias}.id > :sinceId`, { sinceId: sinceId });
@ -24,32 +27,32 @@ export function makePaginationQuery<T>(
}
if (sinceDate && untilDate) {
q.andWhere(`(${q.alias}.createdAt, ${q.alias}.id) > (:sinceDate, :sinceId)`, {
q.andWhere(`(${q.alias}.${timeColumn}, ${q.alias}.id) > (:sinceDate, :sinceId)`, {
sinceDate: new Date(sinceDate),
sinceId: sinceId,
});
q.andWhere(`(${q.alias}.createdAt, ${q.alias}.id) < (:untilDate, :untilId)`, {
q.andWhere(`(${q.alias}.${timeColumn}, ${q.alias}.id) < (:untilDate, :untilId)`, {
untilDate: new Date(untilDate),
untilId: untilId,
});
q.orderBy(`${q.alias}.createdAt`, "DESC");
q.orderBy(`${q.alias}.${timeColumn}`, "DESC");
q.addOrderBy(`${q.alias}.id`, "DESC");
} else if (sinceDate) {
q.andWhere(`(${q.alias}.createdAt, ${q.alias}.id) > (:sinceDate, :sinceId)`, {
q.andWhere(`(${q.alias}.${timeColumn}, ${q.alias}.id) > (:sinceDate, :sinceId)`, {
sinceDate: new Date(sinceDate),
sinceId: sinceId,
});
q.orderBy(`${q.alias}.createdAt`, "ASC");
q.orderBy(`${q.alias}.${timeColumn}`, "ASC");
q.addOrderBy(`${q.alias}.id`, "ASC");
} else if (untilDate) {
q.andWhere(`(${q.alias}.createdAt, ${q.alias}.id) < (:untilDate, :untilId)`, {
q.andWhere(`(${q.alias}.${timeColumn}, ${q.alias}.id) < (:untilDate, :untilId)`, {
untilDate: new Date(untilDate),
untilId: untilId,
});
q.orderBy(`${q.alias}.createdAt`, "DESC");
q.orderBy(`${q.alias}.${timeColumn}`, "DESC");
q.addOrderBy(`${q.alias}.id`, "DESC");
} else {
q.orderBy(`${q.alias}.createdAt`, "DESC");
q.orderBy(`${q.alias}.${timeColumn}`, "DESC");
q.addOrderBy(`${q.alias}.id`, "DESC");
}
return q;

View File

@ -1,7 +1,7 @@
import define from "../../../define.js";
import { Emojis } from "@/models/index.js";
import { makePaginationQuery } from "../../../common/make-pagination-query.js";
import type { Emoji } from "@/models/entities/emoji.js";
import {Emojis} from "@/models/index.js";
import {makePaginationQuery} from "../../../common/make-pagination-query.js";
import type {Emoji} from "@/models/entities/emoji.js";
//import { sqlLikeEscape } from "@/misc/sql-like-escape.js";
export const meta = {
@ -92,6 +92,9 @@ export default define(meta, paramDef, async (ps) => {
Emojis.createQueryBuilder("emoji"),
ps.sinceId,
ps.untilId,
undefined,
undefined,
"updatedAt"
).andWhere("emoji.host IS NULL");
let emojis: Emoji[];