a tool for shared writing and social publishing

use sort_date to order

+27 -26
+1 -1
app/(home-pages)/discover/PubListing.tsx
··· 62 62 <p> 63 63 Updated{" "} 64 64 {timeAgo( 65 - props.documents_in_publications?.[0]?.documents?.indexed_at || 65 + props.documents_in_publications?.[0]?.documents?.sort_date || 66 66 "", 67 67 )} 68 68 </p>
+8 -8
app/(home-pages)/discover/getPublications.ts
··· 8 8 import { deduplicateByUri } from "src/utils/deduplicateRecords"; 9 9 10 10 export type Cursor = { 11 - indexed_at?: string; 11 + sort_date?: string; 12 12 count?: number; 13 13 uri: string; 14 14 }; ··· 32 32 .or( 33 33 "record->preferences->showInDiscover.is.null,record->preferences->>showInDiscover.eq.true", 34 34 ) 35 - .order("indexed_at", { 35 + .order("documents(sort_date)", { 36 36 referencedTable: "documents_in_publications", 37 37 ascending: false, 38 38 }) ··· 64 64 } else { 65 65 // recentlyUpdated 66 66 const aDate = new Date( 67 - a.documents_in_publications[0]?.indexed_at || 0, 67 + a.documents_in_publications[0]?.documents?.sort_date || 0, 68 68 ).getTime(); 69 69 const bDate = new Date( 70 - b.documents_in_publications[0]?.indexed_at || 0, 70 + b.documents_in_publications[0]?.documents?.sort_date || 0, 71 71 ).getTime(); 72 72 if (bDate !== aDate) { 73 73 return bDate - aDate; ··· 89 89 (pubCount === cursor.count && pub.uri < cursor.uri) 90 90 ); 91 91 } else { 92 - const pubDate = pub.documents_in_publications[0]?.indexed_at || ""; 92 + const pubDate = pub.documents_in_publications[0]?.documents?.sort_date || ""; 93 93 // Find first pub after cursor 94 94 return ( 95 - pubDate < (cursor.indexed_at || "") || 96 - (pubDate === cursor.indexed_at && pub.uri < cursor.uri) 95 + pubDate < (cursor.sort_date || "") || 96 + (pubDate === cursor.sort_date && pub.uri < cursor.uri) 97 97 ); 98 98 } 99 99 }); ··· 117 117 normalizedPage.length > 0 && startIndex + limit < allPubs.length 118 118 ? order === "recentlyUpdated" 119 119 ? { 120 - indexed_at: lastItem.documents_in_publications[0]?.indexed_at, 120 + sort_date: lastItem.documents_in_publications[0]?.documents?.sort_date, 121 121 uri: lastItem.uri, 122 122 } 123 123 : {
+5 -5
app/(home-pages)/p/[didOrHandle]/getProfilePosts.ts
··· 10 10 import { deduplicateByUriOrdered } from "src/utils/deduplicateRecords"; 11 11 12 12 export type Cursor = { 13 - indexed_at: string; 13 + sort_date: string; 14 14 uri: string; 15 15 }; 16 16 ··· 29 29 documents_in_publications(publications(*))`, 30 30 ) 31 31 .like("uri", `at://${did}/%`) 32 - .order("indexed_at", { ascending: false }) 32 + .order("sort_date", { ascending: false }) 33 33 .order("uri", { ascending: false }) 34 34 .limit(limit); 35 35 36 36 if (cursor) { 37 37 query = query.or( 38 - `indexed_at.lt.${cursor.indexed_at},and(indexed_at.eq.${cursor.indexed_at},uri.lt.${cursor.uri})`, 38 + `sort_date.lt.${cursor.sort_date},and(sort_date.eq.${cursor.sort_date},uri.lt.${cursor.uri})`, 39 39 ); 40 40 } 41 41 ··· 79 79 documents: { 80 80 data: normalizedData, 81 81 uri: doc.uri, 82 - indexed_at: doc.indexed_at, 82 + sort_date: doc.sort_date, 83 83 comments_on_documents: doc.comments_on_documents, 84 84 document_mentions_in_bsky: doc.document_mentions_in_bsky, 85 85 }, ··· 99 99 const nextCursor = 100 100 posts.length === limit 101 101 ? { 102 - indexed_at: posts[posts.length - 1].documents.indexed_at, 102 + sort_date: posts[posts.length - 1].documents.sort_date, 103 103 uri: posts[posts.length - 1].documents.uri, 104 104 } 105 105 : null;
+5 -5
app/(home-pages)/reader/getReaderFeed.ts
··· 38 38 "documents_in_publications.publications.publication_subscriptions.identity", 39 39 auth_res.atp_did, 40 40 ) 41 - .order("indexed_at", { ascending: false }) 41 + .order("sort_date", { ascending: false }) 42 42 .order("uri", { ascending: false }) 43 43 .limit(25); 44 44 if (cursor) { 45 45 query = query.or( 46 - `indexed_at.lt.${cursor.timestamp},and(indexed_at.eq.${cursor.timestamp},uri.lt.${cursor.uri})`, 46 + `sort_date.lt.${cursor.timestamp},and(sort_date.eq.${cursor.timestamp},uri.lt.${cursor.uri})`, 47 47 ); 48 48 } 49 49 let { data: rawFeed, error } = await query; ··· 78 78 document_mentions_in_bsky: post.document_mentions_in_bsky, 79 79 data: normalizedData, 80 80 uri: post.uri, 81 - indexed_at: post.indexed_at, 81 + sort_date: post.sort_date, 82 82 }, 83 83 }; 84 84 return p; ··· 88 88 const nextCursor = 89 89 posts.length > 0 90 90 ? { 91 - timestamp: posts[posts.length - 1].documents.indexed_at, 91 + timestamp: posts[posts.length - 1].documents.sort_date, 92 92 uri: posts[posts.length - 1].documents.uri, 93 93 } 94 94 : null; ··· 109 109 documents: { 110 110 data: NormalizedDocument | null; 111 111 uri: string; 112 - indexed_at: string; 112 + sort_date: string; 113 113 comments_on_documents: { count: number }[] | undefined; 114 114 document_mentions_in_bsky: { count: number }[] | undefined; 115 115 };
+2 -2
app/(home-pages)/reader/getSubscriptions.ts
··· 32 32 .select(`*, publications(*, documents_in_publications(*, documents(*)))`) 33 33 .order(`created_at`, { ascending: false }) 34 34 .order(`uri`, { ascending: false }) 35 - .order("indexed_at", { 35 + .order("documents(sort_date)", { 36 36 ascending: false, 37 37 referencedTable: "publications.documents_in_publications", 38 38 }) ··· 85 85 record: NormalizedPublication; 86 86 uri: string; 87 87 documents_in_publications: { 88 - documents: { data?: Json; indexed_at: string } | null; 88 + documents: { data?: Json; sort_date: string } | null; 89 89 }[]; 90 90 };
+2 -2
app/(home-pages)/tag/[tag]/getDocumentsByTag.ts
··· 24 24 documents_in_publications(publications(*))`, 25 25 ) 26 26 .contains("data->tags", `["${tag}"]`) 27 - .order("indexed_at", { ascending: false }) 27 + .order("sort_date", { ascending: false }) 28 28 .limit(50); 29 29 30 30 if (error) { ··· 69 69 document_mentions_in_bsky: doc.document_mentions_in_bsky, 70 70 data: normalizedData, 71 71 uri: doc.uri, 72 - indexed_at: doc.indexed_at, 72 + sort_date: doc.sort_date, 73 73 }, 74 74 }; 75 75 return post;
+1
app/api/rpc/[command]/get_publication_data.ts
··· 83 83 uri: dip.documents.uri, 84 84 record: normalized, 85 85 indexed_at: dip.documents.indexed_at, 86 + sort_date: dip.documents.sort_date, 86 87 data: dip.documents.data, 87 88 commentsCount: dip.documents.comments_on_documents[0]?.count || 0, 88 89 mentionsCount: dip.documents.document_mentions_in_bsky[0]?.count || 0,
+3 -3
feeds/index.ts
··· 116 116 } 117 117 query = query 118 118 .or("data->postRef.not.is.null,data->bskyPostRef.not.is.null") 119 - .order("indexed_at", { ascending: false }) 119 + .order("sort_date", { ascending: false }) 120 120 .order("uri", { ascending: false }) 121 121 .limit(25); 122 122 if (parsedCursor) 123 123 query = query.or( 124 - `indexed_at.lt.${parsedCursor.date},and(indexed_at.eq.${parsedCursor.date},uri.lt.${parsedCursor.uri})`, 124 + `sort_date.lt.${parsedCursor.date},and(sort_date.eq.${parsedCursor.date},uri.lt.${parsedCursor.uri})`, 125 125 ); 126 126 127 127 let { data, error } = await query; ··· 131 131 posts = posts || []; 132 132 133 133 let lastPost = posts[posts.length - 1]; 134 - let newCursor = lastPost ? `${lastPost.indexed_at}::${lastPost.uri}` : null; 134 + let newCursor = lastPost ? `${lastPost.sort_date}::${lastPost.uri}` : null; 135 135 return c.json({ 136 136 cursor: newCursor || cursor, 137 137 feed: posts.flatMap((p) => {