diff --git a/packages/backend/src/server/api/common/make-pagination-query.ts b/packages/backend/src/server/api/common/make-pagination-query.ts index fca8299f3b..2c01db0f8b 100644 --- a/packages/backend/src/server/api/common/make-pagination-query.ts +++ b/packages/backend/src/server/api/common/make-pagination-query.ts @@ -6,7 +6,10 @@ export function makePaginationQuery( 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( } 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; diff --git a/packages/backend/src/server/api/endpoints/admin/emoji/list.ts b/packages/backend/src/server/api/endpoints/admin/emoji/list.ts index f8269588ca..a5afa23148 100644 --- a/packages/backend/src/server/api/endpoints/admin/emoji/list.ts +++ b/packages/backend/src/server/api/endpoints/admin/emoji/list.ts @@ -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[];