Skip to content

Commit

Permalink
Speed up favourites (#422)
Browse files Browse the repository at this point in the history
* Speed up loading favourites

* Remove unused queries
  • Loading branch information
jefflau authored Aug 15, 2019
1 parent 531a540 commit 2cf7229
Show file tree
Hide file tree
Showing 6 changed files with 110 additions and 38 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
"notification-polyfill": "^1.0.0",
"react": "16.7.0-alpha.0",
"react-add-to-calendar": "^0.1.5",
"react-apollo": "^2.1.2",
"react-apollo": "^3.0.0",
"react-dom": "16.7.0-alpha.0",
"react-ga": "^2.5.7",
"react-router": "^4.2.0",
Expand Down
4 changes: 4 additions & 0 deletions src/api/manager/resolvers.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,10 @@ async function getParent(name) {

const resolvers = {
Query: {
getOwner: async (_, { name }, { cache }) => {
const owner = await getOwner(name)
return owner
},
singleName: async (_, { name }, { cache }) => {
try {
const nameArray = name.split('.')
Expand Down
18 changes: 6 additions & 12 deletions src/components/DomainItem/DomainItem.js
Original file line number Diff line number Diff line change
Expand Up @@ -90,9 +90,8 @@ const DomainName = styled('h2')`
color: ${p => {
switch (p.state) {
case 'Yours':
return '#2b2b2b'
case 'Owned':
return '#CCD4DA'
return '#2b2b2b'
default:
return '#2b2b2b'
}
Expand Down Expand Up @@ -128,18 +127,9 @@ const Label = ({ domain, isOwner }) => {
case 'Open':
text = 'Available'
break
case 'Auction':
text = 'Bidding Period'
break
case 'Owned':
text = 'Unavailable'
break
case 'Forbidden':
text = 'Forbidden'
break
case 'Reveal':
text = 'Reveal Period'
break
default:
text = 'Unknown State'
}
Expand Down Expand Up @@ -188,7 +178,11 @@ const Domain = ({ domain, isSubDomain, className, isFavourite, loading }) => {
<Label domain={domain} isOwner={isOwner} />
{isSubDomain && domain.state === 'Open' ? (
<Price className="price">
{domain.price > 0 ? `${domain.price} ETH` : 'Free'}
{domain.price
? domain.price > 0
? `${domain.price} ETH`
: 'Free'
: ''}
</Price>
) : (
''
Expand Down
15 changes: 15 additions & 0 deletions src/graphql/queries.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,21 @@ export const GET_ALL_NODES = gql`
${NodeFields}
`

export const GET_ALL_OWNERS = gql`
query names @client {
owners {
name
owner
}
}
`

export const GET_OWNER = gql`
query getOwner($name: String) @client {
getOwner(name: $name) @client
}
`

export const GET_SINGLE_NAME = gql`
query singleName($name: String) @client {
singleName(name: $name) @client {
Expand Down
22 changes: 17 additions & 5 deletions src/routes/Favourites.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import DomainItem from '../components/DomainItem/DomainItem'
import {
GET_FAVOURITES,
GET_SUBDOMAIN_FAVOURITES,
GET_SINGLE_NAME
GET_OWNER
} from '../graphql/queries'

import mq from 'mediaQuery'
Expand Down Expand Up @@ -65,6 +65,10 @@ const NoDomains = ({ type }) => (
</NoDomainsContainer>
)

function getDomainState(owner) {
return parseInt(owner, 16) === 0 ? 'Open' : 'Owned'
}

class Favourites extends Component {
state = {
hasFavourites: true,
Expand All @@ -87,7 +91,7 @@ class Favourites extends Component {
<>
{data.favourites.map(domain => (
<Query
query={GET_SINGLE_NAME}
query={GET_OWNER}
variables={{ name: domain.name }}
key={domain.name}
>
Expand All @@ -101,7 +105,11 @@ class Favourites extends Component {
return (
<DomainItem
loading={loading}
domain={data.singleName}
domain={{
...domain,
state: getDomainState(data.getOwner),
owner: data.getOwner
}}
isFavourite={true}
/>
)
Expand Down Expand Up @@ -131,7 +139,7 @@ class Favourites extends Component {
<Fragment>
{data.subDomainFavourites.map(domain => (
<Query
query={GET_SINGLE_NAME}
query={GET_OWNER}
variables={{ name: domain.name }}
key={domain.name}
>
Expand All @@ -145,7 +153,11 @@ class Favourites extends Component {
return (
<DomainItem
loading={loading}
domain={data.singleName}
domain={{
...domain,
state: getDomainState(data.getOwner),
owner: data.getOwner
}}
isSubDomain={true}
isFavourite={true}
/>
Expand Down
87 changes: 67 additions & 20 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,55 @@
js-sha3 "^0.7.0"
lodash "^4.17.5"

"@apollo/react-common@^3.0.0":
version "3.0.0"
resolved "https://registry.yarnpkg.com/@apollo/react-common/-/react-common-3.0.0.tgz#2357518c4b3bf1fd680ee2ac114f565f527ec55d"
integrity sha512-EqHASkcmxipy2hU8rja+lD1S1HoTdodKKyJZZ3dgewnAHXnzXnnC3rw1+lkrgXPFsI2n2d2N2LYisD79OCdPmw==
dependencies:
ts-invariant "^0.4.4"
tslib "^1.10.0"

"@apollo/react-components@^3.0.0":
version "3.0.0"
resolved "https://registry.yarnpkg.com/@apollo/react-components/-/react-components-3.0.0.tgz#ca489ff8f70c6a7224f0c2a8a0baedda0448a815"
integrity sha512-IF5HZWT4Vc+6JXenFApjc+QsfZccd7UVSV1Z8l4Y5+EoXkLbmM3fuu8lUQamZqzdVVh6coA8bdI0gafB7PU+1A==
dependencies:
"@apollo/react-common" "^3.0.0"
"@apollo/react-hooks" "^3.0.0"
prop-types "^15.7.2"
ts-invariant "^0.4.4"
tslib "^1.10.0"

"@apollo/react-hoc@^3.0.0":
version "3.0.0"
resolved "https://registry.yarnpkg.com/@apollo/react-hoc/-/react-hoc-3.0.0.tgz#cdcb81f1f28246de1c15d601b9c0c075df18e0f9"
integrity sha512-hZaxumdxHrHtTxzHwY1e7FA43x43dLNhZYLcib8ACbV1W3uH7betPdpzlMcL7aVEL7U+7YwQtbc++e1GxxvTQw==
dependencies:
"@apollo/react-common" "^3.0.0"
"@apollo/react-components" "^3.0.0"
hoist-non-react-statics "^3.3.0"
ts-invariant "^0.4.4"
tslib "^1.10.0"

"@apollo/react-hooks@^3.0.0":
version "3.0.0"
resolved "https://registry.yarnpkg.com/@apollo/react-hooks/-/react-hooks-3.0.0.tgz#5fe4ff7812020f3e1b91b8628af8c03276496d78"
integrity sha512-7kaV6rkx2WZjDYcBmp52oyhTxbNn5Jc4AUmsXZVEnDu9uuvNYURA8bLlJNF8yu4zS7ed8D+ZebC0y0bhrz8wIg==
dependencies:
"@apollo/react-common" "^3.0.0"
"@wry/equality" "^0.1.9"
ts-invariant "^0.4.4"
tslib "^1.10.0"

"@apollo/react-ssr@^3.0.0":
version "3.0.0"
resolved "https://registry.yarnpkg.com/@apollo/react-ssr/-/react-ssr-3.0.0.tgz#a31455f90ec87af0b3b597a6468a9e2732ce738b"
integrity sha512-lgEnvP4lwgqOv4rZA2dDyIcOLdCYkRms54aGxvErHxh7GGfsJFLnx6pRoa+uUvFjr8/edOVQtaHADnaMbtAMbA==
dependencies:
"@apollo/react-common" "^3.0.0"
"@apollo/react-hooks" "^3.0.0"
tslib "^1.10.0"

"@babel/code-frame@7.0.0":
version "7.0.0"
resolved "https://registry.yarnpkg.com/@babel/code-frame/-/code-frame-7.0.0.tgz#06e2ab19bdb535385559aabb5ba59729482800f8"
Expand Down Expand Up @@ -1963,7 +2012,7 @@
"@types/node" ">=6"
tslib "^1.9.3"

"@wry/equality@^0.1.2":
"@wry/equality@^0.1.2", "@wry/equality@^0.1.9":
version "0.1.9"
resolved "https://registry.yarnpkg.com/@wry/equality/-/equality-0.1.9.tgz#b13e18b7a8053c6858aa6c85b54911fb31e3a909"
integrity sha512-mB6ceGjpMGz1ZTza8HYnrPGos2mC6So4NhS1PtZ8s4Qt0K7fBiIGhpSxUbQmhwcSWE3no+bYxmI2OL6KuXYmoQ==
Expand Down Expand Up @@ -8340,11 +8389,6 @@ lodash.difference@^4.0.2:
resolved "https://registry.yarnpkg.com/lodash.difference/-/lodash.difference-4.5.0.tgz#9ccb4e505d486b91651345772885a2df27fd017c"
integrity sha1-nMtOUF1Ia5FlE0V3KIWi3yf9AXw=

lodash.isequal@^4.5.0:
version "4.5.0"
resolved "https://registry.yarnpkg.com/lodash.isequal/-/lodash.isequal-4.5.0.tgz#415c4478f2bcc30120c22ce10ed3226f7d3e18e0"
integrity sha1-QVxEePK8wwEgwizhDtMib30+GOA=

lodash.keyby@^4.6.0:
version "4.6.0"
resolved "https://registry.yarnpkg.com/lodash.keyby/-/lodash.keyby-4.6.0.tgz#7f6a1abda93fd24e22728a4d361ed8bcba5a4354"
Expand Down Expand Up @@ -10925,18 +10969,16 @@ react-add-to-calendar@^0.1.5:
optionalDependencies:
moment "^2.18.1"

react-apollo@^2.1.2:
version "2.5.8"
resolved "https://registry.yarnpkg.com/react-apollo/-/react-apollo-2.5.8.tgz#c7a593b027efeefdd8399885e0ac6bec3b32623c"
integrity sha512-60yOQrnNosxU/tRbOxGDaYNLFcOKmQqxHPhxyvKTlGIaF/rRCXQRKixUgWVffpEupSHHD7psY5k5ZOuZsdsSGQ==
react-apollo@^3.0.0:
version "3.0.0"
resolved "https://registry.yarnpkg.com/react-apollo/-/react-apollo-3.0.0.tgz#2a0bccd32e11ce86b140d5d0284356972b7e8e11"
integrity sha512-dxUml6Z91kRg/dQhKac2aTwLkDNmDa6APd3jmeGE48nAg0/a282zQryX7HXk0M6l3qaRISclGDhLINqdSXBLyA==
dependencies:
apollo-utilities "^1.3.0"
fast-json-stable-stringify "^2.0.0"
hoist-non-react-statics "^3.3.0"
lodash.isequal "^4.5.0"
prop-types "^15.7.2"
ts-invariant "^0.4.2"
tslib "^1.9.3"
"@apollo/react-common" "^3.0.0"
"@apollo/react-components" "^3.0.0"
"@apollo/react-hoc" "^3.0.0"
"@apollo/react-hooks" "^3.0.0"
"@apollo/react-ssr" "^3.0.0"

react-app-polyfill@^1.0.1:
version "1.0.1"
Expand Down Expand Up @@ -11008,7 +11050,12 @@ react-input-autosize@^2.2.1:
dependencies:
prop-types "^15.5.8"

react-is@^16.7.0, react-is@^16.8.1, react-is@^16.8.4:
react-is@^16.7.0, react-is@^16.8.1:
version "16.9.0"
resolved "https://registry.yarnpkg.com/react-is/-/react-is-16.9.0.tgz#21ca9561399aad0ff1a7701c01683e8ca981edcb"
integrity sha512-tJBzzzIgnnRfEm046qRcURvwQnZVXmuCbscxUO5RWrGTXpon2d4c8mI0D8WE6ydVIm29JiLB6+RslkIvym9Rjw==

react-is@^16.8.4:
version "16.8.6"
resolved "https://registry.yarnpkg.com/react-is/-/react-is-16.8.6.tgz#5bbc1e2d29141c9fbdfed456343fe2bc430a6a16"
integrity sha512-aUk3bHfZ2bRSVFFbbeVS4i+lNPZr3/WM5jT2J5omUVV1zzcs1nAaf3l51ctA5FFvCRbhrH0bdAsRRQddFJZPtA==
Expand Down Expand Up @@ -12971,7 +13018,7 @@ ts-invariant@^0.3.2:
dependencies:
tslib "^1.9.3"

ts-invariant@^0.4.0, ts-invariant@^0.4.2:
ts-invariant@^0.4.0, ts-invariant@^0.4.4:
version "0.4.4"
resolved "https://registry.yarnpkg.com/ts-invariant/-/ts-invariant-0.4.4.tgz#97a523518688f93aafad01b0e80eb803eb2abd86"
integrity sha512-uEtWkFM/sdZvRNNDL3Ehu4WVpwaulhwQszV8mrtcdeE8nN00BV9mAmQ88RkrBhFgl9gMgvjJLAQcZbnPXI9mlA==
Expand All @@ -12983,7 +13030,7 @@ ts-pnp@1.1.2, ts-pnp@^1.0.0:
resolved "https://registry.yarnpkg.com/ts-pnp/-/ts-pnp-1.1.2.tgz#be8e4bfce5d00f0f58e0666a82260c34a57af552"
integrity sha512-f5Knjh7XCyRIzoC/z1Su1yLLRrPrFCgtUAh/9fCSP6NKbATwpOL1+idQVXQokK9GRFURn/jYPGPfegIctwunoA==

tslib@^1.8.1, tslib@^1.9.0, tslib@^1.9.3:
tslib@^1.10.0, tslib@^1.8.1, tslib@^1.9.0, tslib@^1.9.3:
version "1.10.0"
resolved "https://registry.yarnpkg.com/tslib/-/tslib-1.10.0.tgz#c3c19f95973fb0a62973fb09d90d961ee43e5c8a"
integrity sha512-qOebF53frne81cf0S9B41ByenJ3/IuH8yJKngAX35CmiZySA0khhkovshKK+jGCaMnVomla7gVlIcc3EvKPbTQ==
Expand Down

0 comments on commit 2cf7229

Please sign in to comment.