-
Notifications
You must be signed in to change notification settings - Fork 3
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
please make the last changes then can merge. dont forget to rebase.
oh forgot the tests, lets wait on merging until tests are done.
// calculate winning for this user in this event | ||
let winning = '0'; | ||
if (resultIndex === event.currentResultIndex) { | ||
const res = await MultipleResultsEventApi.calculateWinnings({ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we would still have the parallel limit issue here since the limit()
is only for the outer promise. let me dig into this issue and lets leave this for now.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can we move the limit to wrap this part so no inner promises?
We query the bets and resultsets first, then start to limit.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's use https://caolan.github.io/async/v3/docs.html#eachOfSeries to handle the calculateWinnings
and keep the outer limit promise. Would prefer not to limit the logic on the inside of an already parallel promise. Not too familiar with the logic of limit to start placing it in the middle of async parallel execution. Not too sure what would happen.
This will be slower since its running each calcWinnings individually but this ensures the concurrency limit is not broken.
// calculate winning for this user in this event | ||
let winning = '0'; | ||
if (resultIndex === event.currentResultIndex) { | ||
const res = await MultipleResultsEventApi.calculateWinnings({ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's use https://caolan.github.io/async/v3/docs.html#eachOfSeries to handle the calculateWinnings
and keep the outer limit promise. Would prefer not to limit the logic on the inside of an already parallel promise. Not too familiar with the logic of limit to start placing it in the middle of async parallel execution. Not too sure what would happen.
This will be slower since its running each calcWinnings individually but this ensures the concurrency limit is not broken.
src/sync/update-leaderboard.js
Outdated
reject(err); | ||
} | ||
})); | ||
async.forEachOf(filtered, (value, key, callback) => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
forgot to change to use eachOfSeries
. Will change and test later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
please change before this gets merged, eachOf
still is doing parallel exec.
@@ -418,19 +418,19 @@ type Query { | |||
skip: Int | |||
): PaginatedBiggestWinner! | |||
|
|||
eventLeaderboard( | |||
filter: LeaderboardFilter | |||
eventLeaderboardEntries( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should still be eventLeaderboard
. Sorry wasn't clear. The eventLeaderboard
query returns a list of LeaderboardEntry
s. Like a users
query will return a list of User
s.
The relation is one-to-many. One eventLeaderboard
query will return many LeaderboardEntry
s.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Think eventLeaderboardEntries
works better since we are querying for a set of paginated entries not the whole leaderboard.
In Event store, we only query for one specific entry just to get the winnings.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fair enough. Actually it does conform to the other query names.
|
||
globalLeaderboard( | ||
filter: LeaderboardFilter | ||
globalLeaderboardEntries( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same thing here
src/sync/update-leaderboard.js
Outdated
reject(err); | ||
} | ||
})); | ||
async.forEachOf(filtered, (value, key, callback) => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
please change before this gets merged, eachOf
still is doing parallel exec.
@@ -418,19 +418,19 @@ type Query { | |||
skip: Int | |||
): PaginatedBiggestWinner! | |||
|
|||
eventLeaderboard( | |||
filter: LeaderboardFilter | |||
eventLeaderboardEntries( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fair enough. Actually it does conform to the other query names.
src/graphql/queries/leaderboard.js
Outdated
|
||
if (orderBy && orderBy.length > 0) { | ||
const { field } = orderBy[0]; | ||
res.items.sort((a, b) => new BigNumber(b[field]).comparedTo(new BigNumber(a[field]))); // all descending |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what if trying to sort by address?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: suggest to maybe use BN.js
in this case. not sure if the performance impacts with BigNumber
would come into play here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
field
here is either investments
or winnings
, which are all converted from BigNumber
instances, think it's better to keep it consistent to use BigNumber
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- Need to handle what happens if someone passes in
{ field: 'eventAddress', direction: 'ASC' }
orbetterAddress
. It will crash here since you're trying to convert an address to a BigNumber. - Was just worried about the performance of it. If you feel the performance is good compared to BN, then let's just keep it BigNumber. But would like to still use BN whenever possible to keep it standardized throughout the code.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ratio is float type, think it's better keep it consistent to use Bignumber still
I will skip the sorting if it's address
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah right, ya if dealing w/ floats, then BigNumber all the way.
3696c89
to
deeea38
Compare
#267 #265
Create eventLeaderboard and globalLeaderboard tables and models
Make db helper methods for both tables
In sync, every bet, result set, vote
amounts
goes into eventLeaderboardinvestment
In sync, when event goes to
WITHDRAWING
status, updateeventLeaderboard winnings and returnRatio
In sync, when event goes to
WITHDRAWING
status, updateglobalLeaderboard investments, winnings and returnRatio
Migration
Testings
Queries