Make initial News loading faster
This commit is contained in:
@@ -1,6 +1,6 @@
|
|||||||
services:
|
services:
|
||||||
website:
|
website:
|
||||||
image: ghcr.io/bewcloud/bewcloud:v2.6.0
|
image: ghcr.io/bewcloud/bewcloud:v2.6.1
|
||||||
restart: always
|
restart: always
|
||||||
ports:
|
ports:
|
||||||
- 127.0.0.1:8000:8000
|
- 127.0.0.1:8000:8000
|
||||||
|
|||||||
@@ -15,6 +15,8 @@ interface Filter {
|
|||||||
status: 'all' | 'unread';
|
status: 'all' | 'unread';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let hasFetchedAllArticlesOnce = false;
|
||||||
|
|
||||||
export default function Articles({ initialArticles }: ArticlesProps) {
|
export default function Articles({ initialArticles }: ArticlesProps) {
|
||||||
const isRefreshing = useSignal<boolean>(false);
|
const isRefreshing = useSignal<boolean>(false);
|
||||||
const articles = useSignal<NewsFeedArticle[]>(initialArticles);
|
const articles = useSignal<NewsFeedArticle[]>(initialArticles);
|
||||||
@@ -148,6 +150,11 @@ export default function Articles({ initialArticles }: ArticlesProps) {
|
|||||||
function setNewFilter(newFilter: Partial<Filter>) {
|
function setNewFilter(newFilter: Partial<Filter>) {
|
||||||
filter.value = { ...filter.value, ...newFilter };
|
filter.value = { ...filter.value, ...newFilter };
|
||||||
|
|
||||||
|
if (newFilter.status === 'all' && !hasFetchedAllArticlesOnce) {
|
||||||
|
refreshArticles();
|
||||||
|
hasFetchedAllArticlesOnce = true;
|
||||||
|
}
|
||||||
|
|
||||||
isFilterDropdownOpen.value = false;
|
isFilterDropdownOpen.value = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -214,6 +214,17 @@ export class ArticleModel {
|
|||||||
return articles;
|
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) {
|
static async listByFeedId(feedId: string) {
|
||||||
const articles = await db.query<NewsFeedArticle>(
|
const articles = await db.query<NewsFeedArticle>(
|
||||||
sql`SELECT * FROM "bewcloud_news_feed_articles" WHERE "feed_id" = $1 ORDER BY "article_date" DESC`,
|
sql`SELECT * FROM "bewcloud_news_feed_articles" WHERE "feed_id" = $1 ORDER BY "article_date" DESC`,
|
||||||
|
|||||||
@@ -19,7 +19,7 @@ export const handler: Handlers<Data, FreshContextState> = {
|
|||||||
return new Response('Redirect', { status: 303, headers: { 'Location': `/dashboard` } });
|
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 });
|
return await context.render({ userArticles });
|
||||||
},
|
},
|
||||||
|
|||||||
Reference in New Issue
Block a user