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

Function updateFeedAndAdsCache

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

Source from the content-addressed store, hash-verified

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

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