Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add a max page to avoid huge queries #185

Merged
merged 1 commit into from
May 25, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions webapp/src/components/NFTListPage/NFTListPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ import {
} from '../../modules/nft/wearable/types'
import { NFTCategory } from '../../modules/nft/types'
import { getSortOrder } from '../../modules/nft/utils'
import { MAX_QUERY_SIZE, PAGE_SIZE } from '../../lib/api/client'
import { MAX_QUERY_SIZE, MAX_PAGE, PAGE_SIZE } from '../../lib/api/client'
import { NFTCard } from '../NFTCard'
import { CategoriesMenu } from '../CategoriesMenu'
import { Props } from './NFTListPage.types'
Expand Down Expand Up @@ -294,7 +294,7 @@ const NFTListPage = (props: Props) => {

// Kick things off
useEffect(() => {
const skip = offset * PAGE_SIZE
const skip = Math.min(offset, MAX_PAGE) * PAGE_SIZE
const first = Math.min(page * PAGE_SIZE - skip, MAX_QUERY_SIZE)

const category = getSearchCategory(section)
Expand Down Expand Up @@ -519,7 +519,8 @@ const NFTListPage = (props: Props) => {
<div className="load-more">
{nfts.length >= PAGE_SIZE &&
nfts.length > lastNFTLength &&
(nfts.length !== count || count === MAX_QUERY_SIZE) ? (
(nfts.length !== count || count === MAX_QUERY_SIZE) &&
page <= MAX_PAGE ? (
<Button
loading={isLoading}
inverted
Expand Down
1 change: 1 addition & 0 deletions webapp/src/lib/api/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { InMemoryCache } from 'apollo-cache-inmemory'
import { HttpLink } from 'apollo-link-http'

export const MAX_QUERY_SIZE = 1000
export const MAX_PAGE = 10000
export const PAGE_SIZE = 24
export const MARKETPLACE_URL = process.env.REACT_APP_MARKETPLACE_URL

Expand Down