Skip to content

Commit

Permalink
Use pages for getting VOTER actions
Browse files Browse the repository at this point in the history
  • Loading branch information
lmcorbalan committed Jan 4, 2021
1 parent 6d38eb5 commit 059d592
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 66 deletions.
42 changes: 17 additions & 25 deletions src/hooks/queries.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -109,17 +109,25 @@ export const POLLS_FIRST_QUERY = gql`
`
const getPollsData = (pageIndex, pageSize, offset, ordering) => {
return `
polls_${pageIndex}: polls(first: ${pageSize}, skip: ${offset}, ${ordering}, where: { id_not_in: [0,1,2,3,6,7,8,9,11] }) {
...pollsDetail
}
polls_${pageIndex}: polls(first: ${pageSize}, skip: ${offset}, ${ordering}, where: { id_not_in: [0,1,2,3,6,7,8,9,11] }) {
...pollsDetail
}
`
}

const getExecutivesData = (pageIndex, pageSize, offset, ordering) => {
return `
executives_${pageIndex}: spells(first: ${pageSize}, skip: ${offset}, ${ordering}) {
...executivesDetailHome
}
executives_${pageIndex}: spells(first: ${pageSize}, skip: ${offset}, ${ordering}) {
...executivesDetailHome
}
`
}

const getVotersData = (pageIndex, pageSize, offset, ordering) => {
return `
voters_${pageIndex}: actions(where: { type: VOTER }, first: ${pageSize}, skip: ${offset}, ${ordering}) {
...actionsDetail
}
`
}

Expand All @@ -143,27 +151,11 @@ const getHomeData = (pageIndex, pageSize, offset, ordering) => {
`
}

export const HOME_DATA_QUERY2 = gql`
query getHomeData2($voters: Int!) {
${getAllEvents(getPollsData, 'startDate')}
${getAllEvents(getExecutivesData)}
voters: actions(where: { type: VOTER }, first: $voters) {
...actionsDetail
}
${getAllEvents(getHomeData)}
}
${pollsDetailFragment}
${executivesDetailFragment}
${actionsDetailFragment}
`

export const HOME_DATA_QUERY = ({ pollPages, executivesPages }) => gql`
query getHomeData($voters: Int!) {
export const HOME_DATA_QUERY = ({ pollPages, executivesPages, votersPages }) => gql`
query getHomeData {
${getAllEvents(getExecutivesData, 'timestamp', executivesPages)}
${getAllEvents(getPollsData, 'startDate', pollPages)}
voters: actions(where: { type: VOTER }, first: $voters) {
...actionsDetail
}
${getAllEvents(getVotersData, 'timestamp', votersPages)}
${getAllEvents(getHomeData)}
}
${pollsDetailFragment}
Expand Down
10 changes: 2 additions & 8 deletions src/hooks/useHomeData.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,25 +7,20 @@ import { mergeEventPages } from '../utils'

const REACT_APP_HOME_DATA_TTL = Number(process.env.REACT_APP_HOME_DATA_TTL) || 5

const getHomeVariables = data => {
const governance = data.governanceInfo
return {
voters: Number(governance.countProxies) + Number(governance.countAddresses) || 1000,
}
}

const getPages = gData => {
if (!gData) {
return {
pollPages: 2,
executivesPages: 2,
votersPages: 1,
}
}

const { governanceInfo } = gData
return {
pollPages: Math.ceil(Number(governanceInfo.countPolls) / 1000),
executivesPages: Math.ceil(Number(governanceInfo.countSpells) / 1000),
votersPages: Math.ceil((Number(governanceInfo.countProxies) + Number(governanceInfo.countAddresses)) / 1000),
}
}

Expand All @@ -34,7 +29,6 @@ export function useHomeData(governanceInfo: Maybe<any>): any {
const [results, setResults] = useState<Maybe<null>>(null)
const [loading, setLoading] = useState(true)
const { data, error } = useQuery(HOME_DATA_QUERY(getPages(governanceInfo)), {
variables: governanceInfo && getHomeVariables(governanceInfo),
skip: skipQuery,
})

Expand Down
33 changes: 0 additions & 33 deletions src/types/generatedGQL.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1181,39 +1181,6 @@ export interface getHistoryDataVariables {
/* eslint-disable */
// This file was automatically generated and should not be edited.

// ====================================================
// GraphQL query operation: getHomeData2
// ====================================================

export interface getHomeData2_voters {
__typename: 'Action'
id: string
/**
* Action timestamp as seconds (time)
*/
timestamp: any
/**
* Action value (arg)
*/
wad: any | null
/**
* Action name (act)
*/
type: ActionType
}

export interface getHomeData2 {
voters: getHomeData2_voters[]
}

export interface getHomeData2Variables {
voters: number
}

/* tslint:disable */
/* eslint-disable */
// This file was automatically generated and should not be edited.

// ====================================================
// GraphQL fragment: executivesDetailPage
// ====================================================
Expand Down

0 comments on commit 059d592

Please sign in to comment.