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

Function updateFeedAndAdsCache

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

Source from the content-addressed store, hash-verified

754};
755
756export const updateFeedAndAdsCache = (
757 postId: string,
758 feedQueryKey: QueryKey,
759 queryClient: QueryClient,
760 update: Partial<Post>,
761): void => {
762 // Update the main feed cache
763 const updateFeedPost = updateCachedPagePost(feedQueryKey, queryClient);
764 const feedData =
765 queryClient.getQueryData<InfiniteData<AnyFeedData>>(feedQueryKey);
766
767 if (feedData) {
768 const { pageIndex, index } = findIndexOfPostInData(feedData, postId, true);
769 if (index > -1) {
770 const currentPost = getFeedApiItemPost(
771 feedData.pages[pageIndex].page.edges[index].node,
772 );
773
774 if (!currentPost) {
775 throw new Error(
776 `Missing post-backed feed item at page ${pageIndex} index ${index}`,
777 );
778 }
779
780 updateFeedPost(pageIndex, index, {
781 ...currentPost,
782 ...update,
783 });
784 }
785 }
786
787 // Update the ads cache if the post exists there
788 const adsQueryKey = [RequestKey.Ads, ...feedQueryKey];
789 const adsData = queryClient.getQueryData<InfiniteData<Ad>>(adsQueryKey);
790
791 if (adsData) {
792 const existingAdPost = adsData.pages.find(
793 (page) => page.data?.post?.id === postId,
794 )?.data?.post;
795
796 if (existingAdPost) {
797 queryClient.setQueryData(adsQueryKey, (currentData: InfiniteData<Ad>) => {
798 return updateAdPostInCache(postId, currentData, update);
799 });
800 }
801 }
802};

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