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

Make search random across all pages #57

Merged
merged 7 commits into from
Nov 30, 2018

Conversation

hemal7735
Copy link
Collaborator

@hemal7735 hemal7735 commented Nov 23, 2018

This PR addresses the concerns shown here: #51 (comment)

How it is done?

I see there is a field called total_count in the response. We can utilize that to figure out the number of pages as default is 30 items per page. So the idea is:

  1. figure out the number of pages
  2. select random page
  3. select random issue from that page

Note:

  • We will be making 2 calls to octokit apis for this. I'm not sure how it will affect rate-limiting.
  • changes to tests in search.spec.js.

@hemal7735 hemal7735 changed the title Make search random across all pages [WIP]: Make search random across all pages Nov 23, 2018
@hemal7735 hemal7735 changed the title [WIP]: Make search random across all pages Make search random across all pages Nov 23, 2018
@bnb
Copy link
Member

bnb commented Nov 23, 2018

Don't worry about build failures – issue with our .travis.yml

@hemal7735
Copy link
Collaborator Author

@bnb I was thinking of using filter operation first and then reduce, rather than filtering inside reduce.

@bnb
Copy link
Member

bnb commented Nov 23, 2018

I think that makes sense 🤔

@ghost
Copy link

ghost commented Nov 23, 2018

If you filter outside the reduce its a bit less performant because you're looping more than once over the items no?

@hemal7735
Copy link
Collaborator Author

If you filter outside the reduce its a bit less performant because you're looping more than once over the items no?

Yes, it might be a tiny bit slower, however, it will be negligible due to the size of the dataset(30 max) that we have. Then it comes down to the readability of code, and that is what pipe and filter pattern excels at. Tomorrow you might want to change the filters based on the user demands, in that case we just need to swap the current filter with something else.

@bnb
Copy link
Member

bnb commented Nov 24, 2018

FWIW it still seems like I'm only getting 1st page with good-first-issue feeling-lucky – all the results are within the last hour (and were the same last night as well). Not sure if you've implemented random selection of pages yet 🤔

@hemal7735
Copy link
Collaborator Author

hemal7735 commented Nov 24, 2018

@bnb great catch. Found it, just es6 things where key can be skipped incase of variable name matches to key!
Sorry for wasting your time! 😞
Initially I had the same keys, then linting asked me to use camelCase .

@hemal7735 hemal7735 changed the title Make search random across all pages [WIP]: Make search random across all pages Nov 24, 2018
@hemal7735 hemal7735 changed the title [WIP]: Make search random across all pages Make search random across all pages Nov 25, 2018
@bnb
Copy link
Member

bnb commented Nov 25, 2018

@hemal7735 no worries! ❤️

@bnb
Copy link
Member

bnb commented Nov 25, 2018

Looks like it's working! I got a few from ~3 hours ago, and one from ~11 months ago. 💥

Only comment is that it looks like some lines don't have test coverage. If you could add that, this should be good to go!

@hemal7735
Copy link
Collaborator Author

@bnb It is 100% now. Can you check with Travis CI?

@bnb
Copy link
Member

bnb commented Nov 30, 2018

Travis checks look good to me. I'll pull this down and test it out a bit, but when I was testing the other day it looked good. Sanity check and we're good to go 👍

@bnb
Copy link
Member

bnb commented Nov 30, 2018

Out of 10-15 tries I got mostly issues within the last 48 hours with good-first-issue feeling-lucky. Not necessarily an issue on the part of this code, just not sure if that's intended or not 🤔

const PER_PAGE = 30
const PAGE = 1 // page_number is 1-based index

// API does not allow more than 1000 results -> tested via "feeling-lucky"
Copy link
Member

Choose a reason for hiding this comment

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

So is it possible to change the starting page (PAGE)? It doesn't seem like we're doing that, which would be a vital part of full randomization right? 🤔

Perhaps I'm just not fully understanding what this code is doing.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

These are the constants and defaults referred in getSearchParams function. Any calls made to octokit.search.issues should use getSearchParams function inorder to properly generate search-params.

now, although these are defaults, one can override them by passing their search param values.
perhaps, I should use Object.assign 😞

Copy link
Collaborator Author

@hemal7735 hemal7735 Nov 30, 2018

Choose a reason for hiding this comment

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

So is it possible to change the starting page (PAGE)?

Yes, we are doing it in the second call made to issues search.

@bnb
Copy link
Member

bnb commented Nov 30, 2018

LGTM. Going to merge this + ship it in v0.17.0 👍

@bnb bnb merged commit a075446 into cutenode:master Nov 30, 2018
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.

None yet

2 participants