mirror of
https://github.com/instaloader/instaloader.git
synced 2024-11-04 09:22:29 +01:00
Cache and reuse profiles for Profile.from_id()
This commit is contained in:
parent
0e534ba519
commit
cc15cb5857
@ -69,6 +69,9 @@ class InstaloaderContext:
|
|||||||
# Can be set to True for testing, disables supression of InstaloaderContext._error_catcher
|
# Can be set to True for testing, disables supression of InstaloaderContext._error_catcher
|
||||||
self.raise_all_errors = False
|
self.raise_all_errors = False
|
||||||
|
|
||||||
|
# Cache profile from id (mapping from id to Profile)
|
||||||
|
self.profile_id_cache = dict()
|
||||||
|
|
||||||
@contextmanager
|
@contextmanager
|
||||||
def anonymous_copy(self):
|
def anonymous_copy(self):
|
||||||
session = self._session
|
session = self._session
|
||||||
|
@ -402,6 +402,8 @@ class Profile:
|
|||||||
:param profile_id: userid
|
:param profile_id: userid
|
||||||
:raises: :class:`ProfileNotExistsException`, :class:`ProfileHasNoPicsException`
|
:raises: :class:`ProfileNotExistsException`, :class:`ProfileHasNoPicsException`
|
||||||
"""
|
"""
|
||||||
|
if profile_id in context.profile_id_cache:
|
||||||
|
return context.profile_id_cache[profile_id]
|
||||||
data = context.graphql_query("472f257a40c653c64c666ce877d59d2b",
|
data = context.graphql_query("472f257a40c653c64c666ce877d59d2b",
|
||||||
{'id': str(profile_id), 'first': 1},
|
{'id': str(profile_id), 'first': 1},
|
||||||
rhx_gis=context.root_rhx_gis)['data']['user']
|
rhx_gis=context.root_rhx_gis)['data']['user']
|
||||||
@ -415,7 +417,9 @@ class Profile:
|
|||||||
raise ProfileHasNoPicsException("Profile with ID {0}: no pics found.".format(str(profile_id)))
|
raise ProfileHasNoPicsException("Profile with ID {0}: no pics found.".format(str(profile_id)))
|
||||||
else:
|
else:
|
||||||
raise LoginRequiredException("Login required to determine username (ID: " + str(profile_id) + ").")
|
raise LoginRequiredException("Login required to determine username (ID: " + str(profile_id) + ").")
|
||||||
return Post(context, data['edges'][0]['node']).owner_profile
|
profile = Post(context, data['edges'][0]['node']).owner_profile
|
||||||
|
context.profile_id_cache[profile_id] = profile
|
||||||
|
return profile
|
||||||
|
|
||||||
def _asdict(self):
|
def _asdict(self):
|
||||||
json_node = self._node.copy()
|
json_node = self._node.copy()
|
||||||
|
Loading…
Reference in New Issue
Block a user