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

Function updateFeedAndAdsCache

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

Source from the content-addressed store, hash-verified

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

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