From 1c680551b603698134ec8a327b7cb243d9775016 Mon Sep 17 00:00:00 2001 From: Jared Pereira Date: Sun, 25 Jan 2026 19:12:35 -0500 Subject: [PATCH] use sort_date to order --- app/(home-pages)/discover/PubListing.tsx | 2 +- app/(home-pages)/discover/getPublications.ts | 16 ++++++++-------- .../p/[didOrHandle]/getProfilePosts.ts | 10 +++++----- app/(home-pages)/reader/getReaderFeed.ts | 10 +++++----- app/(home-pages)/reader/getSubscriptions.ts | 4 ++-- app/(home-pages)/tag/[tag]/getDocumentsByTag.ts | 4 ++-- app/api/rpc/[command]/get_publication_data.ts | 1 + feeds/index.ts | 6 +++--- 8 files changed, 27 insertions(+), 26 deletions(-) diff --git a/app/(home-pages)/discover/PubListing.tsx b/app/(home-pages)/discover/PubListing.tsx index eff5df20..a899c0f4 100644 --- a/app/(home-pages)/discover/PubListing.tsx +++ b/app/(home-pages)/discover/PubListing.tsx @@ -62,7 +62,7 @@ export const PubListing = (

Updated{" "} {timeAgo( - props.documents_in_publications?.[0]?.documents?.indexed_at || + props.documents_in_publications?.[0]?.documents?.sort_date || "", )}

diff --git a/app/(home-pages)/discover/getPublications.ts b/app/(home-pages)/discover/getPublications.ts index ce649276..aa633c1a 100644 --- a/app/(home-pages)/discover/getPublications.ts +++ b/app/(home-pages)/discover/getPublications.ts @@ -8,7 +8,7 @@ import { import { deduplicateByUri } from "src/utils/deduplicateRecords"; export type Cursor = { - indexed_at?: string; + sort_date?: string; count?: number; uri: string; }; @@ -32,7 +32,7 @@ export async function getPublications( .or( "record->preferences->showInDiscover.is.null,record->preferences->>showInDiscover.eq.true", ) - .order("indexed_at", { + .order("documents(sort_date)", { referencedTable: "documents_in_publications", ascending: false, }) @@ -64,10 +64,10 @@ export async function getPublications( } else { // recentlyUpdated const aDate = new Date( - a.documents_in_publications[0]?.indexed_at || 0, + a.documents_in_publications[0]?.documents?.sort_date || 0, ).getTime(); const bDate = new Date( - b.documents_in_publications[0]?.indexed_at || 0, + b.documents_in_publications[0]?.documents?.sort_date || 0, ).getTime(); if (bDate !== aDate) { return bDate - aDate; @@ -89,11 +89,11 @@ export async function getPublications( (pubCount === cursor.count && pub.uri < cursor.uri) ); } else { - const pubDate = pub.documents_in_publications[0]?.indexed_at || ""; + const pubDate = pub.documents_in_publications[0]?.documents?.sort_date || ""; // Find first pub after cursor return ( - pubDate < (cursor.indexed_at || "") || - (pubDate === cursor.indexed_at && pub.uri < cursor.uri) + pubDate < (cursor.sort_date || "") || + (pubDate === cursor.sort_date && pub.uri < cursor.uri) ); } }); @@ -117,7 +117,7 @@ export async function getPublications( normalizedPage.length > 0 && startIndex + limit < allPubs.length ? order === "recentlyUpdated" ? { - indexed_at: lastItem.documents_in_publications[0]?.indexed_at, + sort_date: lastItem.documents_in_publications[0]?.documents?.sort_date, uri: lastItem.uri, } : { diff --git a/app/(home-pages)/p/[didOrHandle]/getProfilePosts.ts b/app/(home-pages)/p/[didOrHandle]/getProfilePosts.ts index 29f98afb..131b821f 100644 --- a/app/(home-pages)/p/[didOrHandle]/getProfilePosts.ts +++ b/app/(home-pages)/p/[didOrHandle]/getProfilePosts.ts @@ -10,7 +10,7 @@ import { import { deduplicateByUriOrdered } from "src/utils/deduplicateRecords"; export type Cursor = { - indexed_at: string; + sort_date: string; uri: string; }; @@ -29,13 +29,13 @@ export async function getProfilePosts( documents_in_publications(publications(*))`, ) .like("uri", `at://${did}/%`) - .order("indexed_at", { ascending: false }) + .order("sort_date", { ascending: false }) .order("uri", { ascending: false }) .limit(limit); if (cursor) { query = query.or( - `indexed_at.lt.${cursor.indexed_at},and(indexed_at.eq.${cursor.indexed_at},uri.lt.${cursor.uri})`, + `sort_date.lt.${cursor.sort_date},and(sort_date.eq.${cursor.sort_date},uri.lt.${cursor.uri})`, ); } @@ -79,7 +79,7 @@ export async function getProfilePosts( documents: { data: normalizedData, uri: doc.uri, - indexed_at: doc.indexed_at, + sort_date: doc.sort_date, comments_on_documents: doc.comments_on_documents, document_mentions_in_bsky: doc.document_mentions_in_bsky, }, @@ -99,7 +99,7 @@ export async function getProfilePosts( const nextCursor = posts.length === limit ? { - indexed_at: posts[posts.length - 1].documents.indexed_at, + sort_date: posts[posts.length - 1].documents.sort_date, uri: posts[posts.length - 1].documents.uri, } : null; diff --git a/app/(home-pages)/reader/getReaderFeed.ts b/app/(home-pages)/reader/getReaderFeed.ts index 753142c7..d3996eb6 100644 --- a/app/(home-pages)/reader/getReaderFeed.ts +++ b/app/(home-pages)/reader/getReaderFeed.ts @@ -38,12 +38,12 @@ export async function getReaderFeed( "documents_in_publications.publications.publication_subscriptions.identity", auth_res.atp_did, ) - .order("indexed_at", { ascending: false }) + .order("sort_date", { ascending: false }) .order("uri", { ascending: false }) .limit(25); if (cursor) { query = query.or( - `indexed_at.lt.${cursor.timestamp},and(indexed_at.eq.${cursor.timestamp},uri.lt.${cursor.uri})`, + `sort_date.lt.${cursor.timestamp},and(sort_date.eq.${cursor.timestamp},uri.lt.${cursor.uri})`, ); } let { data: rawFeed, error } = await query; @@ -78,7 +78,7 @@ export async function getReaderFeed( document_mentions_in_bsky: post.document_mentions_in_bsky, data: normalizedData, uri: post.uri, - indexed_at: post.indexed_at, + sort_date: post.sort_date, }, }; return p; @@ -88,7 +88,7 @@ export async function getReaderFeed( const nextCursor = posts.length > 0 ? { - timestamp: posts[posts.length - 1].documents.indexed_at, + timestamp: posts[posts.length - 1].documents.sort_date, uri: posts[posts.length - 1].documents.uri, } : null; @@ -109,7 +109,7 @@ export type Post = { documents: { data: NormalizedDocument | null; uri: string; - indexed_at: string; + sort_date: string; comments_on_documents: { count: number }[] | undefined; document_mentions_in_bsky: { count: number }[] | undefined; }; diff --git a/app/(home-pages)/reader/getSubscriptions.ts b/app/(home-pages)/reader/getSubscriptions.ts index 3d2d7765..d1b3e6ff 100644 --- a/app/(home-pages)/reader/getSubscriptions.ts +++ b/app/(home-pages)/reader/getSubscriptions.ts @@ -32,7 +32,7 @@ export async function getSubscriptions( .select(`*, publications(*, documents_in_publications(*, documents(*)))`) .order(`created_at`, { ascending: false }) .order(`uri`, { ascending: false }) - .order("indexed_at", { + .order("documents(sort_date)", { ascending: false, referencedTable: "publications.documents_in_publications", }) @@ -85,6 +85,6 @@ export type PublicationSubscription = { record: NormalizedPublication; uri: string; documents_in_publications: { - documents: { data?: Json; indexed_at: string } | null; + documents: { data?: Json; sort_date: string } | null; }[]; }; diff --git a/app/(home-pages)/tag/[tag]/getDocumentsByTag.ts b/app/(home-pages)/tag/[tag]/getDocumentsByTag.ts index b0e266e8..ebaffbe0 100644 --- a/app/(home-pages)/tag/[tag]/getDocumentsByTag.ts +++ b/app/(home-pages)/tag/[tag]/getDocumentsByTag.ts @@ -24,7 +24,7 @@ export async function getDocumentsByTag( documents_in_publications(publications(*))`, ) .contains("data->tags", `["${tag}"]`) - .order("indexed_at", { ascending: false }) + .order("sort_date", { ascending: false }) .limit(50); if (error) { @@ -69,7 +69,7 @@ export async function getDocumentsByTag( document_mentions_in_bsky: doc.document_mentions_in_bsky, data: normalizedData, uri: doc.uri, - indexed_at: doc.indexed_at, + sort_date: doc.sort_date, }, }; return post; diff --git a/app/api/rpc/[command]/get_publication_data.ts b/app/api/rpc/[command]/get_publication_data.ts index 46a04bad..b33b9203 100644 --- a/app/api/rpc/[command]/get_publication_data.ts +++ b/app/api/rpc/[command]/get_publication_data.ts @@ -83,6 +83,7 @@ export const get_publication_data = makeRoute({ uri: dip.documents.uri, record: normalized, indexed_at: dip.documents.indexed_at, + sort_date: dip.documents.sort_date, data: dip.documents.data, commentsCount: dip.documents.comments_on_documents[0]?.count || 0, mentionsCount: dip.documents.document_mentions_in_bsky[0]?.count || 0, diff --git a/feeds/index.ts b/feeds/index.ts index 564dd576..279f5d7c 100644 --- a/feeds/index.ts +++ b/feeds/index.ts @@ -116,12 +116,12 @@ app.get("/xrpc/app.bsky.feed.getFeedSkeleton", async (c) => { } query = query .or("data->postRef.not.is.null,data->bskyPostRef.not.is.null") - .order("indexed_at", { ascending: false }) + .order("sort_date", { ascending: false }) .order("uri", { ascending: false }) .limit(25); if (parsedCursor) query = query.or( - `indexed_at.lt.${parsedCursor.date},and(indexed_at.eq.${parsedCursor.date},uri.lt.${parsedCursor.uri})`, + `sort_date.lt.${parsedCursor.date},and(sort_date.eq.${parsedCursor.date},uri.lt.${parsedCursor.uri})`, ); let { data, error } = await query; @@ -131,7 +131,7 @@ app.get("/xrpc/app.bsky.feed.getFeedSkeleton", async (c) => { posts = posts || []; let lastPost = posts[posts.length - 1]; - let newCursor = lastPost ? `${lastPost.indexed_at}::${lastPost.uri}` : null; + let newCursor = lastPost ? `${lastPost.sort_date}::${lastPost.uri}` : null; return c.json({ cursor: newCursor || cursor, feed: posts.flatMap((p) => { -- 2.51.2