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

Function updateFeedAndAdsCache

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

Source from the content-addressed store, hash-verified

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

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