Skip to content

Commit 3a68b55

Browse files
committed
fix: change adjacent sort strategy by created time
Signed-off-by: Xeu <thankrain@qq.com>
1 parent 13b077d commit 3a68b55

File tree

1 file changed

+17
-7
lines changed

1 file changed

+17
-7
lines changed

server/src/services/feed.ts

+17-7
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
import { and, asc, count, desc, eq, gt, like, lt, or } from "drizzle-orm";
2-
import Elysia, { t } from "elysia";
3-
import { XMLParser } from "fast-xml-parser";
1+
import {and, asc, count, desc, eq, gt, like, lt, or} from "drizzle-orm";
2+
import Elysia, {t} from "elysia";
3+
import {XMLParser} from "fast-xml-parser";
44
import html2md from 'html-to-md';
55
import type {DB} from "../_worker";
66
import {feeds, visits} from "../db/schema";
@@ -231,6 +231,16 @@ export function FeedService() {
231231
id_num = parseInt(id);
232232
}
233233

234+
const feed = await db.query.feeds.findFirst({
235+
where: eq(feeds.id, id_num),
236+
columns: {createdAt: true},
237+
});
238+
if (!feed) {
239+
set.status = 404;
240+
return "Not found";
241+
}
242+
const created_at = feed.createdAt;
243+
234244
const cache = PublicCache();
235245
function formatAndCacheData(
236246
feed: any,
@@ -270,9 +280,9 @@ export function FeedService() {
270280
const tempPreviousFeed = await db.query.feeds.findFirst({
271281
where: and(
272282
and(eq(feeds.draft, 0), eq(feeds.listed, 1)),
273-
lt(feeds.id, id_num),
283+
lt(feeds.createdAt, created_at),
274284
),
275-
orderBy: [desc(feeds.id)],
285+
orderBy: [desc(feeds.createdAt)],
276286
with: {
277287
hashtags: {
278288
columns: {},
@@ -300,9 +310,9 @@ export function FeedService() {
300310
const tempNextFeed = await db.query.feeds.findFirst({
301311
where: and(
302312
and(eq(feeds.draft, 0), eq(feeds.listed, 1)),
303-
gt(feeds.id, id_num),
313+
gt(feeds.createdAt, created_at),
304314
),
305-
orderBy: [asc(feeds.id)],
315+
orderBy: [asc(feeds.createdAt)],
306316
with: {
307317
hashtags: {
308318
columns: {},

0 commit comments

Comments
 (0)