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 endpoint for leaderboards #839

Merged
merged 13 commits into from
Jul 12, 2024
Merged

feat: add endpoint for leaderboards #839

merged 13 commits into from
Jul 12, 2024

Conversation

wa0x6e
Copy link
Contributor

@wa0x6e wa0x6e commented Apr 16, 2024

Following snapshot-labs/snapshot-sequencer#127

Add endpoint to return data from leaderboard table

Test with the query

{
  leaderboards(where: { vote_count_gte: 10, space_in: ["ens.eth"] }) {
    user 
    space 
    votesCount 
    proposalsCount
    lastVote
  }
}

This require that you have run the refresh_leaderboard script from sequencer to populate the table first. user and space can return the full User and Space object.

Leaderboard API is written in order to match the format used in https://api-1.snapshotx.xyz/

Add proposal_count and vote_count to User object

Thanks to the new leaderboard table, we now have access to the total number of votes and proposals created by an user.

{
  user(id: "0xeF8305E140ac520225DAf050e2f71d5fBcC543e7") {
    id 
    votesCount
    proposalsCount
  }
}

Will return

{
  "data": {
    "user": {
      "id": "0xeF8305E140ac520225DAf050e2f71d5fBcC543e7",
      "votesCount": 224,
      "proposalsCount": 217
    }
  }
}

Those 2 new properties have been added to match the User object returned by the SX api

Note

Return properties name are proposalsCount and votesCount for consistency with existing hub API, and not matching the proposal_count and vote_count name on sx

@wa0x6e wa0x6e requested a review from ChaituVR April 16, 2024 19:16
@wa0x6e wa0x6e marked this pull request as draft April 17, 2024 15:31
@wa0x6e wa0x6e marked this pull request as ready for review April 17, 2024 17:12
@wa0x6e wa0x6e marked this pull request as draft April 17, 2024 17:12
@wa0x6e wa0x6e marked this pull request as ready for review April 17, 2024 18:33
@wa0x6e wa0x6e self-assigned this Apr 17, 2024
@wa0x6e
Copy link
Contributor Author

wa0x6e commented May 24, 2024

From my tests, the query is taking ~3s, due to the sorting with votesCount DESC, proposalsCount DESC

  • Removing all sorting drop the query to 400ms
  • Using only one field to sort instead of 2 drop the query to 800ms

Leaderboard is a ranking of top contributors, should be obvious to sort by proposals count if 2 users have the same number of votes, else order will be random

A 3s query should be acceptable, will depend if that scale, as we get more data in the leaderboard table

@wa0x6e wa0x6e requested a review from ChaituVR May 24, 2024 23:11
@wa0x6e
Copy link
Contributor Author

wa0x6e commented May 29, 2024

True that it takes less time, using BINARY casting on only one column.

Still, I just think this PR should be merged only after we resolve the COLLATION issue, and just remove all BINARY casting (and keep the JOIN)

@wa0x6e
Copy link
Contributor Author

wa0x6e commented Jul 10, 2024

Refactored to remove all BINARY casting, query seems to take 200ms now, as fast as the one without JOIN on the leaderboard

@wa0x6e wa0x6e requested a review from ChaituVR July 10, 2024 11:48
Copy link
Member

@ChaituVR ChaituVR left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

tAck

@wa0x6e wa0x6e merged commit 53827e1 into master Jul 12, 2024
2 checks passed
@wa0x6e wa0x6e deleted the feat-add-leaderboard branch July 12, 2024 07:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants