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

View File

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