Refactor article fetching

* Apply different limits to profile and feed
* Ensure the limit is the returned amount
* Pre-sort articles
This commit is contained in:
2024-10-26 12:04:06 +02:00
parent 0b1eca87b2
commit 010eb3f291
4 changed files with 13 additions and 11 deletions

View File

@@ -2,7 +2,6 @@ import { Context } from "@oak/oak";
import { lookupPubkeyByUsername } from "../directory.ts";
import { fetchArticlesByAuthor, fetchProfileEvent } from "../nostr.ts";
import { profileAtomFeed } from "../feeds.ts";
import Article from "../models/article.ts";
import Profile from "../models/profile.ts";
import { notFoundHandler } from "../handlers/errors.ts";
@@ -21,8 +20,7 @@ const userAtomFeedHandler = async function (ctx: Context) {
const profile = new Profile(profileEvent, username);
if (profile.nip05) {
const articleEvents = await fetchArticlesByAuthor(pubkey);
const articles = articleEvents.map((a) => new Article(a));
const articles = await fetchArticlesByAuthor(pubkey, 10);
const atom = await profileAtomFeed(profile, articles);
ctx.response.headers.set("Content-Type", "application/atom+xml");

View File

@@ -1,7 +1,6 @@
import { Context } from "@oak/oak";
import { lookupPubkeyByUsername } from "../directory.ts";
import { fetchArticlesByAuthor, fetchProfileEvent } from "../nostr.ts";
import Article from "../models/article.ts";
import Profile from "../models/profile.ts";
import { profilePageHtml } from "../html.ts";
import { notFoundHandler } from "../handlers/errors.ts";
@@ -20,8 +19,7 @@ const userProfileHandler = async function (ctx: Context) {
if (profileEvent) {
const profile = new Profile(profileEvent, username);
const articleEvents = await fetchArticlesByAuthor(pubkey);
const articles = articleEvents.map((a) => new Article(a));
const articles = await fetchArticlesByAuthor(pubkey, 210);
const html = await profilePageHtml(profile, articles);
generateOgProfileImage(profile);