Skip to content

Commit

Permalink
feat: remove entries total and remaining to reduce big queries
Browse files Browse the repository at this point in the history
  • Loading branch information
DIYgod committed Nov 25, 2024
1 parent e740d4d commit df343b1
Show file tree
Hide file tree
Showing 7 changed files with 27 additions and 47 deletions.
2 changes: 0 additions & 2 deletions apps/renderer/src/modules/entry-column/hooks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}
}

Expand Down
26 changes: 7 additions & 19 deletions apps/renderer/src/modules/entry-column/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 =
Expand Down Expand Up @@ -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} />
)
}
},
Expand All @@ -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,
Expand Down Expand Up @@ -233,17 +223,15 @@ function EntryColumnImpl() {
entryId: null,
})
}
data-total-count={virtuosoOptions.totalCount}
>
{virtuosoOptions.totalCount === 0 &&
{virtuosoOptions.data.length === 0 &&
!entries.isLoading &&
!entries.error &&
feed?.type === "feed" && <AddFeedHelper />}

<EntryListHeader
refetch={entries.refetch}
isRefreshing={isRefreshing}
totalCount={virtuosoOptions.totalCount}
hasUpdate={entries.hasUpdate}
/>

Expand All @@ -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 />
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand All @@ -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>
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand All @@ -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>
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,6 @@ export const AppendTaildingDivider = ({ children }: { children: React.ReactNode
)

export interface EntryListHeaderProps {
totalCount: number
refetch: () => void
isRefreshing: boolean
hasUpdate: boolean
Expand Down
12 changes: 1 addition & 11 deletions apps/renderer/src/store/entry/store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down Expand Up @@ -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
}

Expand Down
17 changes: 15 additions & 2 deletions packages/shared/src/hono.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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: {
Expand Down Expand Up @@ -6827,7 +6842,6 @@ declare const _routes: hono_hono_base.HonoBase<Env, {
};
output: {
code: 0;
remaining: number;
data?: {
entries: {
description: string | null;
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit df343b1

Please sign in to comment.