From 6cf8dd94050cce3288a9e2fb275dca1166fed26c Mon Sep 17 00:00:00 2001 From: Ryan Barrett Date: Sun, 21 Mar 2021 15:58:01 -0700 Subject: [PATCH] add OPTIMIZED_COMMENTS constant for whether get_comments() is constant or linear for snarfed/bridgy#1021 --- granary/facebook.py | 1 + granary/flickr.py | 1 + granary/github.py | 2 +- granary/instagram.py | 1 + granary/reddit.py | 2 ++ granary/source.py | 5 ++++- granary/twitter.py | 1 + 7 files changed, 11 insertions(+), 2 deletions(-) diff --git a/granary/facebook.py b/granary/facebook.py index 6ec939b8..a78e3431 100644 --- a/granary/facebook.py +++ b/granary/facebook.py @@ -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/ diff --git a/granary/flickr.py b/granary/flickr.py index 92c9b7d3..10f389b6 100644 --- a/granary/flickr.py +++ b/granary/flickr.py @@ -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', diff --git a/granary/github.py b/granary/github.py index c1a03247..342d2a58 100644 --- a/granary/github.py +++ b/granary/github.py @@ -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. diff --git a/granary/instagram.py b/granary/instagram.py index e3d2675f..2c7915b5 100644 --- a/granary/instagram.py +++ b/granary/instagram.py @@ -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 = """ diff --git a/granary/reddit.py b/granary/reddit.py index ba2b5c77..5ad7ced3 100644 --- a/granary/reddit.py +++ b/granary/reddit.py @@ -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 diff --git a/granary/source.py b/granary/source.py index f377826d..311e97e6 100644 --- a/granary/source.py +++ b/granary/source.py @@ -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.""" diff --git a/granary/twitter.py b/granary/twitter.py index 368f55cc..91d7220f 100644 --- a/granary/twitter.py +++ b/granary/twitter.py @@ -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