Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ParseResource's need to know they've been loaded
In __getattr__ we check to see if the object has been lazy loaded or not before we try to do attribute lookups. However, once the attributes have been loaded, we never record that. So this changes _init_attrs, which actually does the loading, to record that it's done so. This change took a loop I had that was taking 8-10s to finish down to .5-1s.
- Loading branch information
2fde657
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 seems incorrect. The
_init_attrs
method only does the loading in the case where it was not lazy loaded. If aParseResource
is created with_is_loaded
set toFalse
, the purpose is to signal the__getattr__
method to actually do the loading by callingself.GET
. This is useful when you only pass theobjectId
to__init__
. If you never access the object, it's never loaded. If you do access an attribute of the object, it's first loaded, then_is_loaded
is removed (not set toTrue
), so that it doesn't fetch again.With this commit, lazy loading fails entirely - if you create a
ParseResource
is with_is_loaded
set toFalse
, it's immediately set toTrue
, and accessing any attributes fails, because they were never loaded.If this commit fixed a problem you were experiencing, it could only be if you were passing
_is_loaded = False
, even though you actually also supplied all the attributes to__init__
.I think this commit should be reverted.
2fde657
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.
2fde657
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.
You can see where it actually does the lazy loading here, and it's clear that the it should not load more than once, and it should definitely never load on
__getattr__
if_is_loaded
was never set. Something else was going on in your case. When reverting this commit locally, I'm unable to reproduce any scenario where lazy loading kicks in without setting_is_loaded
to false myself, or using a Pointer. I'm also unable to reproduce any scenarios where lazy loading happens more than once.It looks like this isn't thread-safe, so accessing the same unloaded Pointer from multiple threads might cause it to load more than once, but it doesn't sound like you were running into that.
2fde657
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.