bugfix/Fix multiple pro schedule requests #631
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
When a league is initialized, a get_pro_schedule espn request is done. It's not stored though so when league.box_scores or league.player_info is called, it re-calls the pro schedule request.
This can be fixed by changing this line in the _fetch_teams function from:
pro_schedule = self._get_all_pro_schedule()
to:
self.pro_schedule = self._get_all_pro_schedule()
and then using self.pro_schedule in the other league functions box_Scores and player_info.
Take this basic program:
league = espn_api.basketball.League(...)
player = league.player_info(playerId=[4701230])
box = league.box_scores()
Currently this does the following api requests:
Note the 3 pro schedule requests, #s 3, 6, 8.
With this fix the same program only does the pro schedule request once, when the league is initialized: