-
Notifications
You must be signed in to change notification settings - Fork 2
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
Fellow members fetching #79
Conversation
const requiredRank = Number(ranking); | ||
this.logger.info(`Fetching members of rank '${requiredRank}' or higher`); | ||
|
||
if (this.fellowsCache.size < 1) { |
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 will use data from cache in case if there are more than 1 rule bucket with rank: x?
i don't see any other use case then... right?
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.
It is a map. The idea for this is to fetch all the available fellows once and then we filter per request, instead of fetching them multiple times per required rank.
So if you request in one rule a rank 4, it will already fetch them all, so, if you request later rank 2, all the ranks will be available already.
mockClear(logger); | ||
const members2 = await fellows.getTeamMembers("2"); | ||
expect(members2.length).toBeGreaterThan(0); | ||
expect(logger.debug).not.toHaveBeenCalledWith("Connecting to collective parachain"); |
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 is nice test. do you plan to add the actual rule with rank:2 where you see it allows / or disallows if approver is rank < 2 ?
UPD: ah I see you keep adding stuff :D
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.
That's a good question. I didn't plan on adding it, but maybe it's no trouble at all.
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.
It actually runs out of the box, so that's good!
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.
It actually runs out of the box, so that's good!
where? I haven't seen in this diff changes where the rank: 2 approvals are being tested, could you please point my eyes?
FYI: if there's no test, not a blocker for this PR, just needs to be done now or 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.
I added a test to src/test/runner/runner.test.ts
where it verifies that the user is of a given rank and skips the test.
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.
hmm.. so if author is fellow - it means he doesn't need review? or I don't get
I thought they need to check whether someone who has approved - is a fellow with dan >= X, so then it counts. otherwise the review-bot blocks merge. So I was expecting this kind of test
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.
Looks good, just one thing: do you have plans for invalidating the cache of fellows?
const [address]: [string] = key.toHuman(); | ||
fellows.push({ address, ...(rank.toHuman() as object) } as FellowData); |
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.
Wait, is it basically this?
fellows.push({address: key.toHuman()[0], rank: rank.toHuman()[0]});
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.
Haha yes.
I just used destructuring so that I doesn't look like I'm accessing random array elements which makes it a bit harder to read, but yes.
key
is a string with the address, and rank
is {rank: 1}
.
src/polkadot/fellows.ts
Outdated
await api.disconnect(); | ||
return users; | ||
} catch (error) { | ||
console.error(error); |
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.
But why do we log an error and throw it again? Wouldn't this lead to double logging?
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.
As you have seen in a previous comment, the idea was to log the error, disconnect the API and then throw the error, and, if for some reason, there was a problem during the disconnection of the api, this new error would not overshadow the other error.
const users: Map<string, number> = new Map<string, number>(); | ||
for (const fellow of fellows) { | ||
this.logger.debug(`Fetching identity of '${fellow.address}', rank: ${fellow.rank}`); | ||
const fellowData = (await api.query.identity.identityOf(fellow.address)).toHuman() as |
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.
I feel like this deserves a semaphore, so it could be queried in parallel.
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.
Do you know if there is a limit to stop abuse? That was my main concern.
The current execution takes about 2s, which given the fact that this is an action, is not really a problem (the whole action is executed in about 5s).
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.
Do you know if there is a limit to stop abuse? That was my main concern.
Could you elaborate?
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 problem that we have with GitHub, which has a rate limit.
I assume that there is some kind of rate limit when using Polkadot-JS (else what stop people from DOSing it?), and, because I'm fetching 60 accounts, I found it better to do it in order.
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.
Maybe I'm not understanding you. Could you please elaborate on what you had in mind?
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.
I think we're speaking of the same thing here. I suggest adding a semaphore, so requests would be processed in parallel, but with a limit on how much parallel requests to make.
In gitspiegel
, I've used semaphore-promise library for that.
Check out the usage in core.ts
Co-authored-by: Przemek Rzad <roopert7@gmail.com>
No, as the cache is only generated during the instance and not stored long term. The same as with the GitHub reviews, the cache is only used if we need to fetch the same information during the same execution (that lasts ~5 seconds). So if rule 1 request the teams, we fetch them and cache them, and if rule 2 requests it, we already have them. But once the execution is over the cache disappears with it. |
mockClear(logger); | ||
const members2 = await fellows.getTeamMembers("2"); | ||
expect(members2.length).toBeGreaterThan(0); | ||
expect(logger.debug).not.toHaveBeenCalledWith("Connecting to collective parachain"); |
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.
It actually runs out of the box, so that's good!
where? I haven't seen in this diff changes where the rank: 2 approvals are being tested, could you please point my eyes?
FYI: if there's no test, not a blocker for this PR, just needs to be done now or later
Discussed about the Semaphore and decided to not go with it for this particular case
Created the method to fetch the fellows from the parachain using Polkadot-JS. This will be updated to the new library once it becomes available.
The system fetches all the available fellows with a GitHub handle and caches them. When requesting a fellow, it automatically filters the one it needs and returns an array of handles.
This resolves #61
Co-authored-by: Yuri Volkov mutantcornholio@users.noreply.github.com
Co-authored-by: Maksym Hlukhovtsov mordamax@users.noreply.github.com