Skip to content

Commit 6fc9d09

Browse files
committed
fix: reduce timeline refresh, fixed #1474
Signed-off-by: Innei <tukon479@gmail.com>
1 parent 6ef5622 commit 6fc9d09

File tree

9 files changed

+45
-17
lines changed

9 files changed

+45
-17
lines changed

apps/renderer/src/atoms/settings/general.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ const createDefaultSettings = (): GeneralSettings => ({
1010
// Data control
1111
dataPersist: true,
1212
sendAnonymousData: true,
13+
reduceRefetch: true,
1314

1415
// view
1516
unreadOnly: false,

apps/renderer/src/modules/entry-column/hooks.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ export const useEntryMarkReadHandler = (entriesIds: string[]) => {
5252
}, [feedView, handleMarkReadInRange, handleRenderAsRead, renderAsRead, scrollMarkUnread])
5353
}
5454
const anyString = [] as string[]
55+
5556
export const useEntriesByView = ({
5657
onReset,
5758
isArchived,

apps/renderer/src/modules/settings/tabs/general.tsx

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,10 @@ export const SettingGeneral = () => {
8080
description: t("general.group_by_date.description"),
8181
}),
8282

83+
defineSettingItem("reduceRefetch", {
84+
label: t("general.reduce_refetch.label"),
85+
description: t("general.reduce_refetch.description"),
86+
}),
8387
{ type: "title", value: t("general.unread") },
8488

8589
defineSettingItem("scrollMarkUnread", {

apps/renderer/src/providers/invalidate-query-provider.tsx

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,11 @@ import { IN_ELECTRON } from "@follow/shared/constants"
33
import { useQueryClient } from "@tanstack/react-query"
44
import { useEffect, useRef } from "react"
55

6+
import { useGeneralSettingKey } from "~/atoms/settings/general"
67
import { appLog } from "~/lib/log"
78

8-
const slateTime = 600000 // 10min
9+
const defaultSlateTime = 600_000 // 10min
10+
const maxSlateTime = 6 * 60 * (60 * 1000) // 6hr
911

1012
export class ElectronCloseEvent extends Event {
1113
static type = "electron-close"
@@ -20,6 +22,10 @@ export class ElectronShowEvent extends Event {
2022
}
2123
}
2224

25+
const useSlateTime = () => {
26+
const reduceRefetch = useGeneralSettingKey("reduceRefetch")
27+
return reduceRefetch ? maxSlateTime : defaultSlateTime
28+
}
2329
/**
2430
* Add a event listener to invalidate all queries
2531
*/
@@ -42,6 +48,8 @@ const InvalidateQueryProviderElectron = () => {
4248
}
4349
}, [queryClient])
4450

51+
const slateTime = useSlateTime()
52+
4553
useEffect(() => {
4654
const handler = () => {
4755
const now = Date.now()
@@ -82,6 +90,8 @@ const InvalidateQueryProviderWebApp = () => {
8290

8391
const pageVisibility = usePageVisibility()
8492

93+
const slateTime = useSlateTime()
94+
8595
useEffect(() => {
8696
if (currentVisibilityRef.current === pageVisibility) {
8797
return

apps/renderer/src/queries/entries.ts

Lines changed: 22 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { useGeneralSettingKey } from "~/atoms/settings/general"
12
import { useAuthInfiniteQuery, useAuthQuery } from "~/hooks/common"
23
import { apiClient } from "~/lib/api-fetch"
34
import { defineQuery } from "~/lib/defineQuery"
@@ -125,6 +126,9 @@ export const entries = {
125126
),
126127
}
127128

129+
const maxStaleTime = 6 * 60 * (60 * 1000) // 6 hours
130+
const defaultStaleTime = 10 * (60 * 1000) // 10 minutes
131+
128132
export const useEntries = ({
129133
feedId,
130134
inboxId,
@@ -139,17 +143,24 @@ export const useEntries = ({
139143
view?: number
140144
read?: boolean
141145
isArchived?: boolean
142-
}) =>
143-
useAuthInfiniteQuery(entries.entries({ feedId, inboxId, listId, view, read, isArchived }), {
144-
enabled: feedId !== undefined || inboxId !== undefined || listId !== undefined,
145-
getNextPageParam: (lastPage) =>
146-
inboxId || listId
147-
? lastPage.data?.at(-1)?.entries.insertedAt
148-
: lastPage.data?.at(-1)?.entries.publishedAt,
149-
initialPageParam: undefined,
150-
refetchOnWindowFocus: false,
151-
refetchOnReconnect: false,
152-
})
146+
}) => {
147+
const reduceRefetch = useGeneralSettingKey("reduceRefetch")
148+
return useAuthInfiniteQuery(
149+
entries.entries({ feedId, inboxId, listId, view, read, isArchived }),
150+
{
151+
enabled: feedId !== undefined || inboxId !== undefined || listId !== undefined,
152+
getNextPageParam: (lastPage) =>
153+
inboxId || listId
154+
? lastPage.data?.at(-1)?.entries.insertedAt
155+
: lastPage.data?.at(-1)?.entries.publishedAt,
156+
initialPageParam: undefined,
157+
refetchOnWindowFocus: false,
158+
refetchOnReconnect: false,
159+
160+
staleTime: reduceRefetch ? maxStaleTime : defaultStaleTime,
161+
},
162+
)
163+
}
153164

154165
export const useEntriesPreview = ({ id }: { id?: string }) =>
155166
useAuthQuery(entries.preview(id!), {

apps/server/client/atoms/settings/general.ts

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
import type { GeneralSettings } from "@follow/shared/interface/settings"
22

3-
import { jotaiStore } from "../../lib/store"
43
import { createSettingAtom } from "./helper"
54

6-
const createDefaultSettings = (): GeneralSettings => ({
5+
const createDefaultSettings = (): Partial<GeneralSettings> => ({
76
// App
87
appLaunchOnStartup: false,
98
language: "en",
@@ -22,6 +21,7 @@ const createDefaultSettings = (): GeneralSettings => ({
2221
groupByDate: true,
2322
// Secure
2423
jumpOutLinkWarn: true,
24+
voice: "",
2525
})
2626

2727
export const {
@@ -36,9 +36,6 @@ export const {
3636
settingAtom: __generalSettingAtom,
3737
} = createSettingAtom("general", createDefaultSettings)
3838

39-
export const subscribeShouldUseIndexedDB = (callback: (value: boolean) => void) =>
40-
jotaiStore.sub(__generalSettingAtom, () => callback(getGeneralSettings().dataPersist))
41-
4239
export const generalServerSyncWhiteListKeys: (keyof GeneralSettings)[] = [
4340
"appLaunchOnStartup",
4441
"dataPersist",

changelog/next.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212

1313
- Optimized the Zen mode experience on macOS.
1414
- Improvement web app global shortcuts.
15+
- Optimized the Timeline's data cache, reducing data reloads within a short period of time. You can go to Settings -> General -> Timeline -> Reduce timeline refetch to control this feature, default is enabled.
1516

1617
## Bug Fixes
1718

locales/settings/en.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,8 @@
138138
"general.rebuild_database.title": "Rebuild Database",
139139
"general.rebuild_database.warning.line1": "Rebuilding the database will clear all your local data.",
140140
"general.rebuild_database.warning.line2": "Are you sure you want to continue?",
141+
"general.reduce_refetch.description": "Reduce the data refetch of Timeline, to avoid Timeline being refreshed again when switching between different views.",
142+
"general.reduce_refetch.label": "Reduce timeline refetch",
141143
"general.send_anonymous_data.description": "By opting to send anonymized telemetry data, you contribute to improving the overall user experience of Follow.",
142144
"general.send_anonymous_data.label": "Send anonymous data",
143145
"general.show_unread_on_launch.description": "Show unread content on launch",

packages/shared/src/interface/settings.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ export interface GeneralSettings {
1111
jumpOutLinkWarn: boolean
1212
// TTS
1313
voice: string
14+
reduceRefetch: boolean
1415
}
1516

1617
export interface UISettings {

0 commit comments

Comments
 (0)