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

Function updateFeedAndAdsCache

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

Source from the content-addressed store, hash-verified

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

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