From 684dc533798de4de4f2a67e40728bd54d79d8132 Mon Sep 17 00:00:00 2001 From: Stephen Zhou <38493346+hyoban@users.noreply.github.com> Date: Tue, 8 Jul 2025 17:43:27 +0800 Subject: [PATCH] fix(mobile): persist trending query --- .../mobile/ios/Folo.xcodeproj/project.pbxproj | 2 ++ apps/mobile/src/initialize/hydrate.ts | 21 +++++++++++++++++-- .../src/modules/discover/Recommendations.tsx | 10 +++++++-- apps/mobile/src/modules/discover/Trending.tsx | 3 +++ 4 files changed, 32 insertions(+), 4 deletions(-) diff --git a/apps/mobile/ios/Folo.xcodeproj/project.pbxproj b/apps/mobile/ios/Folo.xcodeproj/project.pbxproj index 9dcc5a222..8279ae128 100644 --- a/apps/mobile/ios/Folo.xcodeproj/project.pbxproj +++ b/apps/mobile/ios/Folo.xcodeproj/project.pbxproj @@ -307,6 +307,7 @@ "${PODS_CONFIGURATION_BUILD_DIR}/PromisesObjC/FBLPromises_Privacy.bundle", "${PODS_CONFIGURATION_BUILD_DIR}/PromisesSwift/Promises_Privacy.bundle", "${PODS_CONFIGURATION_BUILD_DIR}/RCT-Folly/RCT-Folly_privacy.bundle", + "${PODS_CONFIGURATION_BUILD_DIR}/RNDeviceInfo/RNDeviceInfoPrivacyInfo.bundle", "${PODS_CONFIGURATION_BUILD_DIR}/RNSVG/RNSVGFilters.bundle", "${PODS_CONFIGURATION_BUILD_DIR}/ReachabilitySwift/ReachabilitySwift.bundle", "${PODS_CONFIGURATION_BUILD_DIR}/React-Core/React-Core_privacy.bundle", @@ -346,6 +347,7 @@ "${TARGET_BUILD_DIR}/${UNLOCALIZED_RESOURCES_FOLDER_PATH}/FBLPromises_Privacy.bundle", "${TARGET_BUILD_DIR}/${UNLOCALIZED_RESOURCES_FOLDER_PATH}/Promises_Privacy.bundle", "${TARGET_BUILD_DIR}/${UNLOCALIZED_RESOURCES_FOLDER_PATH}/RCT-Folly_privacy.bundle", + "${TARGET_BUILD_DIR}/${UNLOCALIZED_RESOURCES_FOLDER_PATH}/RNDeviceInfoPrivacyInfo.bundle", "${TARGET_BUILD_DIR}/${UNLOCALIZED_RESOURCES_FOLDER_PATH}/RNSVGFilters.bundle", "${TARGET_BUILD_DIR}/${UNLOCALIZED_RESOURCES_FOLDER_PATH}/ReachabilitySwift.bundle", "${TARGET_BUILD_DIR}/${UNLOCALIZED_RESOURCES_FOLDER_PATH}/React-Core_privacy.bundle", diff --git a/apps/mobile/src/initialize/hydrate.ts b/apps/mobile/src/initialize/hydrate.ts index d51102ac4..fb0138d38 100644 --- a/apps/mobile/src/initialize/hydrate.ts +++ b/apps/mobile/src/initialize/hydrate.ts @@ -2,14 +2,31 @@ import { persistQueryClient } from "@tanstack/react-query-persist-client" import { kvStoragePersister, queryClient } from "../lib/query-client" +declare module "@tanstack/react-query" { + interface Meta { + queryMeta: { persist?: boolean } + } + + interface Register extends Meta {} +} + export const hydrateSettings = () => {} export const hydrateQueryClient = () => { persistQueryClient({ queryClient, persister: kvStoragePersister, dehydrateOptions: { - shouldDehydrateQuery(query) { - return query.queryKey.includes("cache") + shouldDehydrateQuery: (query) => { + if (!query.meta?.persist) return false + const queryIsReadyForPersistence = query.state.status === "success" + if (queryIsReadyForPersistence) { + return ( + !((query.state?.data as any)?.pages?.length > 1) && + query.queryKey?.[0] !== "check-eagle" + ) + } else { + return false + } }, shouldDehydrateMutation() { return false diff --git a/apps/mobile/src/modules/discover/Recommendations.tsx b/apps/mobile/src/modules/discover/Recommendations.tsx index 3e1d0afba..ae623b1aa 100644 --- a/apps/mobile/src/modules/discover/Recommendations.tsx +++ b/apps/mobile/src/modules/discover/Recommendations.tsx @@ -129,16 +129,22 @@ export const RecommendationTab: TabComponent<{ const discoverLanguage = useUISettingKey("discoverLanguage") const { data, isLoading } = useQuery({ - queryKey: ["rsshub-popular", "cache", tab.value, discoverLanguage], + queryKey: ["rsshub-popular", tab.value, discoverLanguage], queryFn: () => fetchRsshubPopular(tab.value, LanguageMap[discoverLanguage]).then((res) => res.data), staleTime: 1000 * 60 * 60 * 24, // 1 day + meta: { + persist: true, + }, }) const { data: analysisData, isLoading: isAnalysisLoading } = useQuery({ - queryKey: ["rsshub-analysis", "cache", discoverLanguage], + queryKey: ["rsshub-analysis", discoverLanguage], queryFn: () => fetchRsshubAnalysis(LanguageMap[discoverLanguage]).then((res) => res.data), staleTime: 1000 * 60 * 60 * 24, // 1 day + meta: { + persist: true, + }, }) const keys = useMemo(() => { diff --git a/apps/mobile/src/modules/discover/Trending.tsx b/apps/mobile/src/modules/discover/Trending.tsx index c0cc166df..4fd156c59 100644 --- a/apps/mobile/src/modules/discover/Trending.tsx +++ b/apps/mobile/src/modules/discover/Trending.tsx @@ -32,6 +32,9 @@ export const Trending = ({ lang: discoverLanguage === "all" ? undefined : discoverLanguage, limit: 20, }).then((res) => res.data), + meta: { + persist: true, + }, }) const navigation = useNavigation()