Skip to content

Commit 6cf8dd9

Browse files
committed
add OPTIMIZED_COMMENTS constant for whether get_comments() is constant or linear
for snarfed/bridgy#1021
1 parent 67424c7 commit 6cf8dd9

File tree

7 files changed

+11
-2
lines changed

7 files changed

+11
-2
lines changed

granary/facebook.py

+1
Original file line numberDiff line numberDiff line change
@@ -214,6 +214,7 @@ class Facebook(source.Source):
214214
NAME = 'Facebook'
215215
FRONT_PAGE_TEMPLATE = 'templates/facebook_index.html'
216216
POST_ID_RE = re.compile('^[0-9_:]+$') # see parse_id() for gory details
217+
OPTIMIZED_COMMENTS = True
217218

218219
# HTML snippet for embedding a post.
219220
# https://developers.facebook.com/docs/plugins/embedded-posts/

granary/flickr.py

+1
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ class Flickr(source.Source):
2727
DOMAIN = 'flickr.com'
2828
BASE_URL = 'https://www.flickr.com/'
2929
NAME = 'Flickr'
30+
OPTIMIZED_COMMENTS = False
3031

3132
API_EXTRAS = ','.join(('date_upload', 'date_taken', 'views', 'media',
3233
'description', 'tags', 'machine_tags', 'geo',

granary/github.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -232,7 +232,7 @@ class GitHub(source.Source):
232232
'use_automatic_links': False,
233233
'tag_callback': tag_placeholders,
234234
}
235-
235+
OPTIMIZED_COMMENTS = True
236236

237237
def __init__(self, access_token=None):
238238
"""Constructor.

granary/instagram.py

+1
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ class Instagram(source.Source):
7272
BASE_URL = 'https://www.instagram.com/'
7373
NAME = 'Instagram'
7474
FRONT_PAGE_TEMPLATE = 'templates/instagram_index.html'
75+
OPTIMIZED_COMMENTS = False
7576

7677
EMBED_POST = """
7778
<script async defer src="//platform.instagram.com/en_US/embeds.js"></script>

granary/reddit.py

+2
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,12 @@
2222

2323

2424
class Reddit(source.Source):
25+
"""Reddit source class. See file docstring and Source class for details."""
2526

2627
DOMAIN = 'reddit.com'
2728
BASE_URL = 'https://reddit.com'
2829
NAME = 'Reddit'
30+
OPTIMIZED_COMMENTS = True
2931

3032
def __init__(self, refresh_token):
3133
self.refresh_token = refresh_token

granary/source.py

+4-1
Original file line numberDiff line numberDiff line change
@@ -205,12 +205,15 @@ class Source(object, metaclass=SourceMeta):
205205
Defaults to Twitter's limit, 280 characters as of 2019-10-12.
206206
* TRUNCATE_URL_LENGTH: integer, optional. Number of characters that URLs count
207207
for. Defaults to Twitter's, 23 as of 2019-10-12.
208+
* OPTIMIZED_COMMENTS: boolean, whether :meth:`get_comment()` is optimized and
209+
only fetches the requested comment. If False, :meth:`get_comment()` fetches
210+
many or all of the post's comments to find the requested one.
208211
"""
209-
210212
POST_ID_RE = None
211213
HTML2TEXT_OPTIONS = {}
212214
TRUNCATE_TEXT_LENGTH = None
213215
TRUNCATE_URL_LENGTH = None
216+
OPTIMIZED_COMMENTS = False
214217

215218
def user_url(self, user_id):
216219
"""Returns the URL for a user's profile."""

granary/twitter.py

+1
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,7 @@ class Twitter(source.Source):
133133
NAME = 'Twitter'
134134
FRONT_PAGE_TEMPLATE = 'templates/twitter_index.html'
135135
POST_ID_RE = re.compile('^[0-9]+$')
136+
OPTIMIZED_COMMENTS = True
136137

137138
# HTML snippet for embedding a tweet.
138139
# https://dev.twitter.com/docs/embedded-tweets

0 commit comments

Comments
 (0)