feat: remove entries total and remaining to reduce big queries

This commit is contained in:
DIYgod
2024-11-26 01:36:09 +08:00
parent e740d4da78
commit df343b10d0
7 changed files with 27 additions and 47 deletions
@@ -228,8 +228,6 @@ export const useEntriesByView = ({
}, [query, view]),
entriesIds: sortEntries,
groupedCounts,
totalCount: query.data?.pages?.[0]?.total ?? mergedEntries[view].length,
queryTotalCount: query.data?.pages?.[0]?.total,
}
}
@@ -121,8 +121,8 @@ function EntryColumnImpl() {
!isArchived && !unreadOnly && !isCollection && routeFeedId !== ROUTE_FEED_PENDING
// Determine if the archived button should be shown
const showArchivedButton = commonConditions && entries.totalCount < 40 && feed?.type === "feed"
const hasNoEntries = entries.queryTotalCount === 0 && !entries.isLoading
const showArchivedButton = commonConditions && feed?.type === "feed"
const hasNoEntries = entries.data?.pages?.[0].data?.length === 0 && !entries.isLoading
// Determine if archived entries should be loaded
const shouldLoadArchivedEntries =
@@ -173,13 +173,7 @@ function EntryColumnImpl() {
} else {
if (context?.onlyShowArchivedButton) return null
return (
<EntryItemSkeleton
view={view}
count={Math.min(
entries.data?.pages?.[0].data?.length || 20,
entries.data?.pages.at(-1)?.remaining || 20,
)}
/>
<EntryItemSkeleton view={view} count={entries.data?.pages?.[0].data?.length || 20} />
)
}
},
@@ -196,13 +190,9 @@ function EntryColumnImpl() {
customScrollParent: scrollRef.current!,
initialScrollTop: prevScrollTopMap[routeFeedId || ""] || 0,
totalCount: entries.totalCount,
endReached: useCallback(async () => {
if (!entries.isFetchingNextPage) {
const remaining = entries.data?.pages.at(-1)?.remaining
if (entries.hasNextPage && remaining) {
await entries.fetchNextPage()
}
if (!entries.isFetchingNextPage && entries.hasNextPage) {
await entries.fetchNextPage()
}
}, [entries]),
data: finalEntriesIds,
@@ -233,9 +223,8 @@ function EntryColumnImpl() {
entryId: null,
})
}
data-total-count={virtuosoOptions.totalCount}
>
{virtuosoOptions.totalCount === 0 &&
{virtuosoOptions.data.length === 0 &&
!entries.isLoading &&
!entries.error &&
feed?.type === "feed" && <AddFeedHelper />}
@@ -243,7 +232,6 @@ function EntryColumnImpl() {
<EntryListHeader
refetch={entries.refetch}
isRefreshing={isRefreshing}
totalCount={virtuosoOptions.totalCount}
hasUpdate={entries.hasUpdate}
/>
@@ -252,7 +240,7 @@ function EntryColumnImpl() {
onPullToRefresh={entries.refetch}
key={`${routeFeedId}-${view}`}
>
{virtuosoOptions.totalCount === 0 && !showArchivedButton ? (
{virtuosoOptions.data.length === 0 && !showArchivedButton ? (
entries.isLoading ? null : (
<EntryEmptyList />
)
@@ -30,11 +30,10 @@ import {
} from "./EntryListHeader.shared"
export const EntryListHeader: FC<{
totalCount: number
refetch: () => void
isRefreshing: boolean
hasUpdate: boolean
}> = ({ totalCount, refetch, isRefreshing, hasUpdate }) => {
}> = ({ refetch, isRefreshing, hasUpdate }) => {
const routerParams = useRouteParams()
const { t } = useTranslation()
@@ -55,10 +54,9 @@ export const EntryListHeader: FC<{
</EllipsisHorizontalTextWithTooltip>
</div>
<div className="whitespace-nowrap text-xs font-medium leading-none text-zinc-400">
{totalCount || 0} {t("quantifier.piece", { ns: "common" })}
{unreadOnly && !isInCollectionList ? t("words.unread") : ""}
{t("space", { ns: "common" })}
{t("words.items", { ns: "common", count: totalCount })}
{t("words.items", { ns: "common", count: 2 })}
</div>
</div>
)
@@ -34,12 +34,7 @@ import {
} from "./EntryListHeader.shared"
import { TimelineTabs } from "./TimelineTabs"
export const EntryListHeader: FC<EntryListHeaderProps> = ({
totalCount,
refetch,
isRefreshing,
hasUpdate,
}) => {
export const EntryListHeader: FC<EntryListHeaderProps> = ({ refetch, isRefreshing, hasUpdate }) => {
const routerParams = useRouteParams()
const { t } = useTranslation()
@@ -62,10 +57,9 @@ export const EntryListHeader: FC<EntryListHeaderProps> = ({
</EllipsisHorizontalTextWithTooltip>
</div>
<div className="whitespace-nowrap text-xs font-medium leading-none text-zinc-400">
{totalCount || 0} {t("quantifier.piece", { ns: "common" })}
{unreadOnly && !isInCollectionList ? t("words.unread") : ""}
{t("space", { ns: "common" })}
{t("words.items", { ns: "common", count: totalCount })}
{t("words.items", { ns: "common", count: 2 })}
</div>
</div>
)
@@ -149,7 +149,6 @@ export const AppendTaildingDivider = ({ children }: { children: React.ReactNode
)
export interface EntryListHeaderProps {
totalCount: number
refetch: () => void
isRefreshing: boolean
hasUpdate: boolean
+1 -11
View File
@@ -7,7 +7,7 @@ import type {
InboxModel,
} from "@follow/models/types"
import type { EntryReadHistoriesModel } from "@follow/shared/hono"
import { isBizId, omitObjectUndefinedValue } from "@follow/utils/utils"
import { omitObjectUndefinedValue } from "@follow/utils/utils"
import { isNil, merge, omit } from "es-toolkit/compat"
import { produce } from "immer"
@@ -163,16 +163,6 @@ class EntryActions {
if (data.data) {
this.upsertMany(data.data, { isArchived })
}
// Sync unread count if fetch unread feedId entries
if (
read === false &&
typeof feedId === "string" &&
isBizId(feedId) &&
typeof data.total === "number"
) {
feedUnreadActions.updateByFeedId(feedId, data.total)
}
return data
}
+15 -2
View File
@@ -5364,6 +5364,21 @@ declare const _routes: hono_hono_base.HonoBase<Env, {
status: 200;
};
};
"/metrics/pools": {
$get: {
input: {};
output: {
code: 0;
data: {
totalCount: number;
idleCount: number;
waitingCount: number;
}[];
};
outputFormat: "json" | "text";
status: 200;
};
};
} & {
"/lists": {
$get: {
@@ -6827,7 +6842,6 @@ declare const _routes: hono_hono_base.HonoBase<Env, {
};
output: {
code: 0;
remaining: number;
data?: {
entries: {
description: string | null;
@@ -6912,7 +6926,6 @@ declare const _routes: hono_hono_base.HonoBase<Env, {
webhooks?: string[] | undefined;
} | undefined;
}[] | undefined;
total?: number | undefined;
};
outputFormat: "json" | "text";
status: 200;