MCPcopy Create free account
hub / github.com/dailydotdev/apps / updateFeedAndAdsCache

Function updateFeedAndAdsCache

packages/shared/src/lib/query.ts:774–820  ·  view source on GitHub ↗
(
  postId: string,
  feedQueryKey: QueryKey,
  queryClient: QueryClient,
  update: Partial<Post>,
)

Source from the content-addressed store, hash-verified

772};
773
774export const updateFeedAndAdsCache = (
775 postId: string,
776 feedQueryKey: QueryKey,
777 queryClient: QueryClient,
778 update: Partial<Post>,
779): void => {
780 // Update the main feed cache
781 const updateFeedPost = updateCachedPagePost(feedQueryKey, queryClient);
782 const feedData =
783 queryClient.getQueryData<InfiniteData<AnyFeedData>>(feedQueryKey);
784
785 if (feedData) {
786 const { pageIndex, index } = findIndexOfPostInData(feedData, postId, true);
787 if (index > -1) {
788 const currentPost = getFeedApiItemPost(
789 feedData.pages[pageIndex].page.edges[index].node,
790 );
791
792 if (!currentPost) {
793 throw new Error(
794 `Missing post-backed feed item at page ${pageIndex} index ${index}`,
795 );
796 }
797
798 updateFeedPost(pageIndex, index, {
799 ...currentPost,
800 ...update,
801 });
802 }
803 }
804
805 // Update the ads cache if the post exists there
806 const adsQueryKey = [RequestKey.Ads, ...feedQueryKey];
807 const adsData = queryClient.getQueryData<InfiniteData<Ad>>(adsQueryKey);
808
809 if (adsData) {
810 const existingAdPost = adsData.pages.find(
811 (page) => page.data?.post?.id === postId,
812 )?.data?.post;
813
814 if (existingAdPost) {
815 queryClient.setQueryData(adsQueryKey, (currentData: InfiniteData<Ad>) => {
816 return updateAdPostInCache(postId, currentData, update);
817 });
818 }
819 }
820};

Callers 3

useOnPostClickFunction · 0.90
usePostFeedbackFunction · 0.90
useFeedOnPostClickFunction · 0.90

Calls 4

getFeedApiItemPostFunction · 0.90
updateCachedPagePostFunction · 0.85
findIndexOfPostInDataFunction · 0.85
updateAdPostInCacheFunction · 0.85

Tested by

no test coverage detected