Skip to content

Commit

Permalink
Reduce ForumPost requests on category pages (Joystream#4523)
Browse files Browse the repository at this point in the history
Fix 4484 : only using FetchPolicy at this moment
  • Loading branch information
mkbeefcake authored and Josh Groban committed Oct 16, 2023
1 parent a4988b1 commit 51fe521
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 3 deletions.
7 changes: 5 additions & 2 deletions packages/ui/src/forum/hooks/useCategoryLatestPost.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import * as Apollo from '@apollo/client'
import { useEffect } from 'react'

import { ForumPostOrderByInput, ForumThreadOrderByInput } from '@/common/api/queries'
import { useGetForumPostsLazyQuery, useGetForumThreadsQuery } from '@/forum/queries'
import { GetForumPostsDocument, useGetForumThreadsQuery } from '@/forum/queries'
import { asForumPost, asForumThread } from '@/forum/types'

export const useCategoryLatestPost = (category_eq: string) => {
Expand All @@ -25,7 +26,9 @@ export const useCategoryLatestPost = (category_eq: string) => {
})
}, [threadData])

const [fetchPost, { data: postData, loading: loadingPosts }] = useGetForumPostsLazyQuery()
const [fetchPost, { data: postData, loading: loadingPosts }] = Apollo.useLazyQuery(GetForumPostsDocument, {
fetchPolicy: 'cache-first',
})
const rawPost = postData?.forumPosts[0]

return {
Expand Down
1 change: 1 addition & 0 deletions packages/ui/src/forum/hooks/useForumCategoryThreadCount.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ export const useForumCategoryThreadCount = (category_eq: string, isArchive?: boo
}
const { data } = useGetForumThreadsCountQuery({
variables: { where: { category: { id_eq: category_eq }, status_json } },
fetchPolicy: 'cache-first',
})
return { threadCount: data?.forumThreadsConnection.totalCount }
}
1 change: 1 addition & 0 deletions packages/ui/src/forum/hooks/useForumPopularThreads.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ export const useForumPopularThreads = ({ categoryId, page = 1, threadsPerPage =
offset: (page - 1) * threadsPerPage,
limit: threadsPerPage,
},
fetchPolicy: 'cache-first',
})

return {
Expand Down
2 changes: 1 addition & 1 deletion packages/ui/src/forum/hooks/useThreadLatestPost.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ const orderBy = [ForumPostOrderByInput.UpdatedAtDesc]

export const useThreadLatestPost = (threadId: string) => {
const where = useMemo((): ForumPostWhereInput => ({ thread: { id_eq: threadId }, isVisible_eq: true }), [threadId])
const { data } = useGetForumPostsQuery({ variables: { where, orderBy, limit: 1 } })
const { data } = useGetForumPostsQuery({ variables: { where, orderBy, limit: 1 }, fetchPolicy: 'cache-first' })
const rawPost = data?.forumPosts[0]
return { post: rawPost && asForumPost(rawPost) }
}

0 comments on commit 51fe521

Please sign in to comment.