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

Limit reviews upto date specified. #13040

Merged
merged 10 commits into from
Aug 30, 2018

Conversation

scorpion35
Copy link
Contributor

Issue: #13030

Solution: Added an optional upto_date parameter to get_review methods. By limiting get_reviews upto a certain date, the time to return from the method is reduced from hours to seconds!

Examples -
Before: Time taken to get all reviews: ~ upto 2 hours (best case). Up to 5 hours (worst case), and the script crashes in the end.

2018-08-03 11:14:33 PM -04 EDT - INFO - [apple_reviews] | Finding all available reviews for "bundleid1" ...
2018-08-04 02:18:39 AM -04 EDT - INFO - [apple_reviews] | Found 90,000 reviews.
...
2018-08-03 11:14:33 PM -04 EDT - INFO - [apple_reviews] | Finding all available reviews for "bundleid2" ...
2018-08-04 02:18:39 AM -04 EDT - ERROR - [apple_reviews] | It seems the script crashed in iteration 1 while getting reviews for App: "bundleid2".

After: Time taken to get reviews up to a specified date: ~ 2 secs (best case) to ~ 30 secs.

2018-08-05 12:41:00 PM -04 EDT - INFO - [apple_reviews] | Finding all available reviews ...
2018-08-05 12:41:02 PM -04 EDT - INFO - [apple_reviews] | 	Found 100 reviews upto date "2018-07-01"
...
2018-08-05 12:40:12 PM -04 EDT - INFO - [apple_reviews] | Finding all available reviews ...
2018-08-05 12:40:38 PM -04 EDT - INFO - [apple_reviews] | 	Found 1700 reviews upto date "2018-07-01"

@googlebot
Copy link

Thanks for your pull request. It looks like this may be your first contribution to a Google open source project (if not, look below for help). Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

📝 Please visit https://cla.developers.google.com/ to sign.

Once you've signed (or fixed any issues), please reply here (e.g. I signed it!) and we'll verify it.


What to do if you already signed the CLA

Individual signers
Corporate signers

Copy link
Member

@joshdholtz joshdholtz left a comment

Choose a reason for hiding this comment

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

Thanks for making this PR 😊 I probably left too many comments but date stuff is weird 😊

BTW, we probably also want to filter all_reviews with the up to the date specified in the parameter. Right now the date logic is only breaking the loop but not filtering the any that may actually be before the date 🙃

@@ -371,6 +371,12 @@ def get_reviews(app_id, platform, storefront, version_id)

r = request(:get, rating_url)
all_reviews.concat(parse_response(r, 'data')['reviews'])

last_review_date = Date.parse(Time.at(all_reviews[-1]['value']['lastModified']/1000).to_s).to_date
if last_review_date < DateTime.parse(upto_date).to_date
Copy link
Member

Choose a reason for hiding this comment

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

Can we move the DateTime.parse(upto_date).to_date to a variable before the loop do so that this operation oly needs to happen once 😊

Also, we should be able to just use Time.parse and then remove the Date.parse on line 375 (see comment on 375)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@@ -46,8 +46,8 @@ def average_rating
end

# @return (Array) of Review Objects
def reviews(store_front = '', version_id = '')
raw_reviews = client.get_reviews(application.apple_id, application.platform, store_front, version_id)
def reviews(store_front = '', version_id = '', upto_date = '')
Copy link
Member

Choose a reason for hiding this comment

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

Can we make upto_date = '' default to nil instead?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@@ -371,6 +371,12 @@ def get_reviews(app_id, platform, storefront, version_id)

r = request(:get, rating_url)
all_reviews.concat(parse_response(r, 'data')['reviews'])

last_review_date = Date.parse(Time.at(all_reviews[-1]['value']['lastModified']/1000).to_s).to_date
Copy link
Member

Choose a reason for hiding this comment

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

We should be able to just do Time.at(all_reviews[-1]['value']['lastModified']/1000) and compare on time (see comment below)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done! e846dd1#diff-64843dee7bf6cf0342bd0e57d9b43c2b

Please take a look and let me know if you'd like to change it to something else.

@@ -358,7 +358,7 @@ def get_ratings(app_id, platform, version_id = '', storefront = '')
parse_response(r, 'data')
end

def get_reviews(app_id, platform, storefront, version_id)
def get_reviews(app_id, platform, storefront, version_id, upto_date)
Copy link
Member

Choose a reason for hiding this comment

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

Can you change this upto_date to default to nil like upto_date = nil to make this backwards compatible? There will need to be an if check below in the logic to check to make sure this upto_date isn't nil then but that logic is okay to have in here 😊

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@scorpion35
Copy link
Contributor Author

@joshdholtz Have made changes suggested by you! Kindly take a look and let me know if you need me to do anything else.

Copy link
Member

@joshdholtz joshdholtz left a comment

Choose a reason for hiding this comment

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

Got a few more small comments! It also looks like the tests are failing and so is the linting. So if you could also ...

  1. Fix existing tests
  2. Add new tests that use the new parameter
  3. Run rubocop (the linter) by running rubocop -a && rubocop -D
  4. Sign CLA

Looking forward to getting this merged after these steps 😊

@@ -371,13 +374,20 @@ def get_reviews(app_id, platform, storefront, version_id)

r = request(:get, rating_url)
all_reviews.concat(parse_response(r, 'data')['reviews'])
last_review_date = Time.at(all_reviews[-1]['value']['lastModified']/1000)

break if last_review_date < upto_date && !upto_date.nil?
Copy link
Member

Choose a reason for hiding this comment

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

I would probably make this break and filter here something like this...

if upto_date && last_review_date < upto_date
  all_reviews = all_reviews.select { |review| Time.at(review['value']['lastModified']/1000) > upto_date  }
  break
end

And then remove the multiple returns at the bottom

Copy link
Contributor Author

Choose a reason for hiding this comment

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

haha cool. I originally had something similar to this, but then I thought I should keep it a one-liner (looked at a couple of other break statements). Changed it to like you suggested!
7c572e2


return all_reviews if upto_date.nil?

return all_reviews.select { |review| Time.at(review['value']['lastModified']/1000) > upto_date }
Copy link
Member

Choose a reason for hiding this comment

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

Remove these multiple returns and just do... (see above comment)

return all_reviews

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done! :)

@scorpion35
Copy link
Contributor Author

@joshdholtz I will add tests tomorrow and look into fixing the linting as well!

@joshdholtz
Copy link
Member

@scorpion35 Sounds great! Just ping me when its ready for a review again 😊

Branch: "reviews_uptodate" | Commit Type: "Bug fix" | Changes tested: "no"
@scorpion35
Copy link
Contributor Author

I signed it!

@googlebot
Copy link

We found a Contributor License Agreement for you (the sender of this pull request), but were unable to find agreements for all the commit author(s) or Co-authors. If you authored these, maybe you used a different email address in the git commits than was used to sign the CLA (login here to double check)? If these were authored by someone else, then they will need to sign a CLA as well, and confirm that they're okay with these being contributed to Google.
In order to pass this check, please resolve this problem and have the pull request author add another comment and the bot will run again. If the bot doesn't comment, it means it doesn't think anything has changed.

@scorpion35
Copy link
Contributor Author

I signed it!

@googlebot
Copy link

So there's good news and bad news.

👍 The good news is that everyone that needs to sign a CLA (the pull request submitter and all commit authors) have done so. Everything is all good there.

😕 The bad news is that it appears that one or more commits were authored or co-authored by someone other than the pull request submitter. We need to confirm that all authors are ok with their commits being contributed to this project. Please have them confirm that here in the pull request.

Note to project maintainer: This is a terminal state, meaning the cla/google commit status will not change from this state. It's up to you to confirm consent of all the commit author(s), set the cla label to yes (if enabled on your project), and then merge this pull request when appropriate.

Prasad Anne added 4 commits August 13, 2018 11:10
Branch: "reviews_uptodate" | Commit Type: "New test" | Changes tested: "no"
Branch: "reviews_uptodate" | Commit Type: "Minor" | Changes tested: "yes"
@scorpion35
Copy link
Contributor Author

scorpion35 commented Aug 13, 2018

@joshdholtz Fixed the linting test. I have also signed the CLA.

I tried to write new tests, but couldn't seem to figure it out. c57e713 & ee69cfe

Could you give me some guidance on how to make a new test, please? I have tried to place a binding.pry in the new test, but the test seems to be stuck forever; not sure what I am doing wrong. Any help is greatly appreciated!

@joshdholtz
Copy link
Member

@scorpion35 Yup, I can help! I'm not sure if I'll have time today but I will look tomorrow/Thursday. Are you cool if I push commits to this PR with tests?

@scorpion35
Copy link
Contributor Author

@joshdholtz Yes, please! Thank you very much :)

I have also signed the CLA (using my both accounts). It seems an admin need to manually set it to yes.

@scorpion35
Copy link
Contributor Author

@joshdholtz Any update, please? :)

@scorpion35
Copy link
Contributor Author

@joshdholtz Any help, please? :) Thanks in advance!

@scorpion35 scorpion35 closed this Aug 28, 2018
@scorpion35 scorpion35 reopened this Aug 28, 2018
@scorpion35
Copy link
Contributor Author

@joshdholtz @taquitos @KrauseFx Kindly let me know how to add tests to Fastlane, please. I tried to add them but wasn't able to figure it out. If you can give me some tips on how to add them, I will try again.

I am trying to move my script to a remote machine but would like to avoid configuring the remote machine to use my custom changes, would prefer to have the machine automatically update to latest version of Fastlane available! :)

Copy link
Collaborator

@taquitos taquitos left a comment

Choose a reason for hiding this comment

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

Lint it up, then everything looks great!
🎈:goat:

@joshdholtz joshdholtz merged commit 413fb07 into fastlane:master Aug 30, 2018
@joshdholtz
Copy link
Member

@scorpion35 Merged! Thanks for making this changing 😊

@scorpion35
Copy link
Contributor Author

You are the best, thank you very much @joshdholtz :)

It seems I over thought about these tests, almost had it (ee69cfe), but over complicated it with some other changes :D haha.

Thanks again! 🙇 Do you know when can I expect these changes in official Fastlane gem?

@fastlane-bot
Copy link

Congratulations! 🎉 This was released as part of fastlane 2.103.0 🚀

janpio pushed a commit to janpio/fastlane that referenced this pull request Sep 11, 2018
* Limit reviews upto date specified.

* Optimizations. Implemented suggestions from comments.

* Removed debug line

* Optimizations and simplified the code so it's easy to read.

* Fixed linting

Branch: "reviews_uptodate" | Commit Type: "Bug fix" | Changes tested: "no"

* Test for reviews upto_date

Branch: "reviews_uptodate" | Commit Type: "New test" | Changes tested: "no"

* Bug fix in upto date test

Branch: "reviews_uptodate" | Commit Type: "Minor" | Changes tested: "yes"

* Revert "Bug fix in upto date test"

This reverts commit ee69cfe.

* Revert "Test for reviews upto_date"

This reverts commit c57e713.

* Added tests for new upto_date parameter
@fastlane fastlane locked and limited conversation to collaborators Nov 4, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants