tangled mirror of catsky-🐱 Soothing soft social-app fork with all the niche toggles! (Unofficial); for issues and PRs please put them on github:NekoDrone/catsky-social

cache pages in explore feed previews (#9082)

authored by samuel.fm and committed by

GitHub ede10368 1127e502

+28 -4
+1 -1
src/screens/Search/Explore.tsx
··· 932 <View style={[a.absolute, a.inset_0, t.atoms.bg, {top: -2}]} /> 933 <ModuleHeader.FeedLink feed={item.feed}> 934 <ModuleHeader.FeedAvatar feed={item.feed} /> 935 - <View style={[a.flex_1, a.gap_xs]}> 936 <ModuleHeader.TitleText style={[a.text_lg]}> 937 {item.feed.displayName} 938 </ModuleHeader.TitleText>
··· 932 <View style={[a.absolute, a.inset_0, t.atoms.bg, {top: -2}]} /> 933 <ModuleHeader.FeedLink feed={item.feed}> 934 <ModuleHeader.FeedAvatar feed={item.feed} /> 935 + <View style={[a.flex_1, a.gap_2xs]}> 936 <ModuleHeader.TitleText style={[a.text_lg]}> 937 {item.feed.displayName} 938 </ModuleHeader.TitleText>
+27 -3
src/state/queries/explore-feed-previews.tsx
··· 1 - import {useMemo} from 'react' 2 import { 3 type AppBskyActorDefs, 4 AppBskyFeedDefs, ··· 127 const moderationOpts = useModerationOpts() 128 const enabled = feeds.length > 0 && isEnabled 129 130 const query = useInfiniteQuery({ 131 enabled, 132 queryKey: RQKEY(uris), ··· 181 } else if (data) { 182 for (let pageIndex = 0; pageIndex < data.pages.length; pageIndex++) { 183 const page = data.pages[pageIndex] 184 // default feed tuner - we just want it to slice up the feed 185 const tuner = new FeedTuner([]) 186 const slices: FeedPreviewItem[] = [] ··· 280 rowIndex++ 281 } 282 283 if (slices.length > 0) { 284 - items.push( 285 { 286 type: 'preview:header', 287 key: `header-${page.feed.uri}`, ··· 292 type: 'preview:footer', 293 key: `footer-${page.feed.uri}`, 294 }, 295 - ) 296 } 297 } 298 } else if (isError && !isEmpty) { 299 items.push({
··· 1 + import {useMemo, useRef} from 'react' 2 import { 3 type AppBskyActorDefs, 4 AppBskyFeedDefs, ··· 127 const moderationOpts = useModerationOpts() 128 const enabled = feeds.length > 0 && isEnabled 129 130 + const processedPageCache = useRef( 131 + new Map< 132 + { 133 + feed: AppBskyFeedDefs.GeneratorView 134 + posts: AppBskyFeedDefs.FeedViewPost[] 135 + }, 136 + FeedPreviewItem[] 137 + >(), 138 + ) 139 + 140 const query = useInfiniteQuery({ 141 enabled, 142 queryKey: RQKEY(uris), ··· 191 } else if (data) { 192 for (let pageIndex = 0; pageIndex < data.pages.length; pageIndex++) { 193 const page = data.pages[pageIndex] 194 + 195 + const cachedPage = processedPageCache.current.get(page) 196 + if (cachedPage) { 197 + items.push(...cachedPage) 198 + continue 199 + } 200 + 201 // default feed tuner - we just want it to slice up the feed 202 const tuner = new FeedTuner([]) 203 const slices: FeedPreviewItem[] = [] ··· 297 rowIndex++ 298 } 299 300 + let processedPage: FeedPreviewItem[] 301 + 302 if (slices.length > 0) { 303 + processedPage = [ 304 { 305 type: 'preview:header', 306 key: `header-${page.feed.uri}`, ··· 311 type: 'preview:footer', 312 key: `footer-${page.feed.uri}`, 313 }, 314 + ] 315 + } else { 316 + processedPage = [] 317 } 318 + 319 + processedPageCache.current.set(page, processedPage) 320 + items.push(...processedPage) 321 } 322 } else if (isError && !isEmpty) { 323 items.push({