-
Notifications
You must be signed in to change notification settings - Fork 197
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: separate leaderboard query on users query (#891)
* fix: count leaderboard entry as valid user * fix: delegate field alias handling to helper * fix: delete unused field * fix: fix invalid id assignment * fix: remove unused params * fix: `users` query should return user if exists in only leaderboard or users table * Revert "fix: `users` query should return user if exists in only leaderboard or users table" This reverts commit 6371ce8. * fix: only return if user exist * fix: only return results if user exist * fix: seperate leaderboard query on users query * Update src/graphql/helpers.ts * fix user query * fix: optimize query * Revert "fix: optimize query" This reverts commit 6e854b3. * Update src/graphql/operations/users.ts * Query leaderboard only to users who don't have a created * remove logs * Use left join and COALESCE * Update src/graphql/operations/users.ts * chore: lint fix --------- Co-authored-by: Wan Qi Chen <[email protected]>
- Loading branch information
Showing
3 changed files
with
46 additions
and
32 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,14 @@ | ||
import { capture } from '@snapshot-labs/snapshot-sentry'; | ||
import db from '../../helpers/mysql'; | ||
import log from '../../helpers/log'; | ||
import { formatUser, formatAddresses, PublicError } from '../helpers'; | ||
import { formatAddresses, PublicError } from '../helpers'; | ||
import users from './users'; | ||
|
||
export default async function (parent, args) { | ||
const addresses = formatAddresses([args.id]); | ||
if (!addresses.length) throw new PublicError('Invalid address'); | ||
const usersObject = await users(parent, { | ||
first: 1, | ||
skip: 0, | ||
where: { id: addresses[0] } | ||
}); | ||
|
||
const query = `SELECT u.* FROM users u WHERE id = ? LIMIT 1`; | ||
|
||
try { | ||
const users = await db.queryAsync(query, addresses[0]); | ||
if (users.length === 1) return formatUser(users[0]); | ||
return null; | ||
} catch (e: any) { | ||
log.error(`[graphql] user, ${JSON.stringify(e)}`); | ||
capture(e, { args }); | ||
return Promise.reject(new Error('request failed')); | ||
} | ||
return usersObject[0] || null; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters