Skip to content

Conversation

@VishakhaSainani-Josh
Copy link
Collaborator

  1. Get all users ranking
  2. Get current user ranking


serviceLeaderboard := make([]LeaderboardUser, len(leaderboard))
for i, l := range leaderboard {
serviceLeaderboard[i] = LeaderboardUser((l))
Copy link
Collaborator

Choose a reason for hiding this comment

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

extra bracket

}

func (s *service) GetAllUsersRank(ctx context.Context) ([]LeaderboardUser, error) {
leaderboard, err := s.userRepository.GetAllUsersRank(ctx, nil)
Copy link
Collaborator

Choose a reason for hiding this comment

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

leaderboard naming is bit confusing, could you change it.
userRanks would be good, so that can update the serviceLeaderboard to leaderboard if needed.

Comment on lines +58 to +66
getAllUsersRankQuery = `
SELECT
id,
github_username,
avatar_url,
current_balance,
RANK() over (ORDER BY current_balance DESC) AS rank
FROM users
ORDER BY current_balance DESC`
Copy link
Collaborator

Choose a reason for hiding this comment

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

Do we have index on current_balance?, would be good to add an index on it when using RANK()

CREATE INDEX idx_users_current_balance ON users(current_balance DESC);

}

func (ur *userRepository) GetCurrentUserRank(ctx context.Context, tx *sqlx.Tx) (LeaderboardUser, error) {
userIdValue := ctx.Value(middleware.UserIdKey)
Copy link
Collaborator

Choose a reason for hiding this comment

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

read ctx in handler, and pass it through service and then repo.
Keep repo layer independent of context value.

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.

4 participants