Make initial News loading faster

This commit is contained in:
Bruno Bernardino
2025-10-01 14:17:39 +01:00
parent adde693585
commit 1dcbf529a3
4 changed files with 20 additions and 2 deletions

View File

@@ -1,6 +1,6 @@
services:
website:
image: ghcr.io/bewcloud/bewcloud:v2.6.0
image: ghcr.io/bewcloud/bewcloud:v2.6.1
restart: always
ports:
- 127.0.0.1:8000:8000

View File

@@ -15,6 +15,8 @@ interface Filter {
status: 'all' | 'unread';
}
let hasFetchedAllArticlesOnce = false;
export default function Articles({ initialArticles }: ArticlesProps) {
const isRefreshing = useSignal<boolean>(false);
const articles = useSignal<NewsFeedArticle[]>(initialArticles);
@@ -148,6 +150,11 @@ export default function Articles({ initialArticles }: ArticlesProps) {
function setNewFilter(newFilter: Partial<Filter>) {
filter.value = { ...filter.value, ...newFilter };
if (newFilter.status === 'all' && !hasFetchedAllArticlesOnce) {
refreshArticles();
hasFetchedAllArticlesOnce = true;
}
isFilterDropdownOpen.value = false;
}

View File

@@ -214,6 +214,17 @@ export class ArticleModel {
return articles;
}
static async listUnread(userId: string) {
const articles = await db.query<NewsFeedArticle>(
sql`SELECT * FROM "bewcloud_news_feed_articles" WHERE "user_id" = $1 AND "is_read" = FALSE ORDER BY "article_date" DESC`,
[
userId,
],
);
return articles;
}
static async listByFeedId(feedId: string) {
const articles = await db.query<NewsFeedArticle>(
sql`SELECT * FROM "bewcloud_news_feed_articles" WHERE "feed_id" = $1 ORDER BY "article_date" DESC`,

View File

@@ -19,7 +19,7 @@ export const handler: Handlers<Data, FreshContextState> = {
return new Response('Redirect', { status: 303, headers: { 'Location': `/dashboard` } });
}
const userArticles = await ArticleModel.list(context.state.user.id);
const userArticles = await ArticleModel.listUnread(context.state.user.id);
return await context.render({ userArticles });
},