Speed up accessing property comments
of Post
This has been asked for in #436.
This commit is contained in:
@@ -325,6 +325,11 @@ class Post:
|
|||||||
@property
|
@property
|
||||||
def comments(self) -> int:
|
def comments(self) -> int:
|
||||||
"""Comment count including answers"""
|
"""Comment count including answers"""
|
||||||
|
# If the count is already present in `self._node`, do not use `self._field` which could trigger fetching the
|
||||||
|
# full metadata dict.
|
||||||
|
comments = self._node.get('edge_media_to_comment')
|
||||||
|
if comments and 'count' in comments:
|
||||||
|
return comments['count']
|
||||||
try:
|
try:
|
||||||
return self._field('edge_media_to_parent_comment', 'count')
|
return self._field('edge_media_to_parent_comment', 'count')
|
||||||
except KeyError:
|
except KeyError:
|
||||||
|
Reference in New Issue
Block a user