Optimize subscription feed retrieval and rendering

This commit is contained in:
thePR0M3TH3AN committed 2025-10-20 21:04:52 -04:00
1 parent a8cea0b147
commit e49483d34d
4 files changed
+139 -11

No files matched your search

+16 -1
View File
@@ -92,12 +92,19 @@ export function createSubscriptionAuthorsSource({ service } = {}) {
return [];
}
const limitCandidate = Number(context?.runtime?.limit);
const limit =
Number.isFinite(limitCandidate) && limitCandidate > 0
? Math.floor(limitCandidate)
: null;
const options = {
blacklistedEventIds: toSet(context?.runtime?.blacklistedEventIds),
isAuthorBlocked:
typeof context?.runtime?.isAuthorBlocked === "function"
? context.runtime.isAuthorBlocked
: () => false,
limit,
};
const authorList = Array.from(authors);
@@ -129,7 +136,15 @@ export function createSubscriptionAuthorsSource({ service } = {}) {
return author && authors.has(author);
});
return filtered.map((video) => ({
const sorted = filtered
.slice()
.sort(
(a, b) => (Number(b?.created_at) || 0) - (Number(a?.created_at) || 0)
);
const limited = limit ? sorted.slice(0, limit) : sorted;
return limited.map((video) => ({
video,
metadata: {
source: "nostr:subscriptions",