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