Closed tarasyarema closed 3 years ago
Thanks for your comments! Good point with the call of has_more
before data
. I implemented a helper method _compute_starting_pos
that computes the staring position before has_more
and data
. Plus, the way it fetches the list is with the getattr
function as you mentioned. I put it this way because in the code there are some time that arbitrary elements are appended to the list after the init, so we need to check for the starting position every time (if given).
Made a simple refactor.
The value self._starting_pos
is not really used as its dynamically computed, so it's transferred to the method self._starting_pos()
.
Thanks, this new version looks good!
Made a simple refactor.
I think it was better before this commit refactor: simplification
, because when exported to JSON, computing the start index (which can be a heavy operation) is done twice, at least. With the previous version, it was done only once.
Beware that the function name _compute_staring_pos()
has a typo (missing t
).
Can you also squash all commits into one with a consistent commit message?
Done @adrienverge !
Btw, don't know why the tests failed only for Python 3.8.
I don't really get what you mean with the computing start... The function is invoked two times, but once the value is set we do not go in the loop, hence the heavy computation is only done once (?)
@tarasyarema you can add a debugging line to see whether the loop is entered only once, or more:
@@ -1556,6 +1556,7 @@ class List(StripeObject):
return
# Only traverse the list when starting_after is given
+ print('entering heavy computation...', flush=True)
for i, item in enumerate(self._list):
if getattr(item, 'id', None) == self._starting_after:
self._starting_pos = i + 1
Oh sorry, I forgot about the _starting_after
... Lemme change it
Tested the different resources with starting_after
parameter and it works only computing one time the _starting_pos
.
@tarasyarema I asked you to double checked before I have to review yet another time, and there are still multiple problems:
self._starting_pos = None
inside __init__()
, and compute it only if it's still None, inside _compute_starting_pos()
. Do not reassign self._starting_after
.test.sh
(again).Pushed the changes. Few comments:
Thanks for merging! About the docker image, will it be updated too?
It will on the next release; probably after #165 and #167 and reviewed and merged.
implements
starting_after
query param forList
as noted in #168