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

Function updateFeedAndAdsCache

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

Source from the content-addressed store, hash-verified

729};
730
731export const updateFeedAndAdsCache = (
732 postId: string,
733 feedQueryKey: QueryKey,
734 queryClient: QueryClient,
735 update: Partial<Post>,
736): void => {
737 // Update the main feed cache
738 const updateFeedPost = updateCachedPagePost(feedQueryKey, queryClient);
739 const feedData =
740 queryClient.getQueryData<InfiniteData<AnyFeedData>>(feedQueryKey);
741
742 if (feedData) {
743 const { pageIndex, index } = findIndexOfPostInData(feedData, postId, true);
744 if (index > -1) {
745 const currentPost = getFeedApiItemPost(
746 feedData.pages[pageIndex].page.edges[index].node,
747 );
748
749 if (!currentPost) {
750 throw new Error(
751 `Missing post-backed feed item at page ${pageIndex} index ${index}`,
752 );
753 }
754
755 updateFeedPost(pageIndex, index, {
756 ...currentPost,
757 ...update,
758 });
759 }
760 }
761
762 // Update the ads cache if the post exists there
763 const adsQueryKey = [RequestKey.Ads, ...feedQueryKey];
764 const adsData = queryClient.getQueryData<InfiniteData<Ad>>(adsQueryKey);
765
766 if (adsData) {
767 const existingAdPost = adsData.pages.find(
768 (page) => page.data?.post?.id === postId,
769 )?.data?.post;
770
771 if (existingAdPost) {
772 queryClient.setQueryData(adsQueryKey, (currentData: InfiniteData<Ad>) => {
773 return updateAdPostInCache(postId, currentData, update);
774 });
775 }
776 }
777};

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