Skip to content

Commit

Permalink
add OPTIMIZED_COMMENTS constant for whether get_comments() is constan…
Browse files Browse the repository at this point in the history
…t or linear

for snarfed/bridgy#1021
  • Loading branch information
snarfed committed Mar 21, 2021
1 parent 67424c7 commit 6cf8dd9
Show file tree
Hide file tree
Showing 7 changed files with 11 additions and 2 deletions.
1 change: 1 addition & 0 deletions granary/facebook.py
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,7 @@ class Facebook(source.Source):
NAME = 'Facebook'
FRONT_PAGE_TEMPLATE = 'templates/facebook_index.html'
POST_ID_RE = re.compile('^[0-9_:]+$') # see parse_id() for gory details
OPTIMIZED_COMMENTS = True

# HTML snippet for embedding a post.
# https://developers.facebook.com/docs/plugins/embedded-posts/
Expand Down
1 change: 1 addition & 0 deletions granary/flickr.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ class Flickr(source.Source):
DOMAIN = 'flickr.com'
BASE_URL = 'https://www.flickr.com/'
NAME = 'Flickr'
OPTIMIZED_COMMENTS = False

API_EXTRAS = ','.join(('date_upload', 'date_taken', 'views', 'media',
'description', 'tags', 'machine_tags', 'geo',
Expand Down
2 changes: 1 addition & 1 deletion granary/github.py
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ class GitHub(source.Source):
'use_automatic_links': False,
'tag_callback': tag_placeholders,
}

OPTIMIZED_COMMENTS = True

def __init__(self, access_token=None):
"""Constructor.
Expand Down
1 change: 1 addition & 0 deletions granary/instagram.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ class Instagram(source.Source):
BASE_URL = 'https://www.instagram.com/'
NAME = 'Instagram'
FRONT_PAGE_TEMPLATE = 'templates/instagram_index.html'
OPTIMIZED_COMMENTS = False

EMBED_POST = """
<script async defer src="//platform.instagram.com/en_US/embeds.js"></script>
Expand Down
2 changes: 2 additions & 0 deletions granary/reddit.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,12 @@


class Reddit(source.Source):
"""Reddit source class. See file docstring and Source class for details."""

DOMAIN = 'reddit.com'
BASE_URL = 'https://reddit.com'
NAME = 'Reddit'
OPTIMIZED_COMMENTS = True

def __init__(self, refresh_token):
self.refresh_token = refresh_token
Expand Down
5 changes: 4 additions & 1 deletion granary/source.py
Original file line number Diff line number Diff line change
Expand Up @@ -205,12 +205,15 @@ class Source(object, metaclass=SourceMeta):
Defaults to Twitter's limit, 280 characters as of 2019-10-12.
* TRUNCATE_URL_LENGTH: integer, optional. Number of characters that URLs count
for. Defaults to Twitter's, 23 as of 2019-10-12.
* OPTIMIZED_COMMENTS: boolean, whether :meth:`get_comment()` is optimized and
only fetches the requested comment. If False, :meth:`get_comment()` fetches
many or all of the post's comments to find the requested one.
"""

POST_ID_RE = None
HTML2TEXT_OPTIONS = {}
TRUNCATE_TEXT_LENGTH = None
TRUNCATE_URL_LENGTH = None
OPTIMIZED_COMMENTS = False

def user_url(self, user_id):
"""Returns the URL for a user's profile."""
Expand Down
1 change: 1 addition & 0 deletions granary/twitter.py
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,7 @@ class Twitter(source.Source):
NAME = 'Twitter'
FRONT_PAGE_TEMPLATE = 'templates/twitter_index.html'
POST_ID_RE = re.compile('^[0-9]+$')
OPTIMIZED_COMMENTS = True

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

0 comments on commit 6cf8dd9

Please sign in to comment.