Skip to content

Commit

Permalink
set last_hfeed_fetch on normal PPD as well as refetch. for #538
Browse files Browse the repository at this point in the history
  • Loading branch information
snarfed committed Nov 7, 2015
1 parent d8df8f0 commit 21e37d7
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 8 deletions.
4 changes: 0 additions & 4 deletions app.py
Expand Up @@ -545,12 +545,8 @@ def post(self):
source, activity, fetch_hfeed=fetch_hfeed, include_redirect_sources=False)
targets |= original_post_discovery.targets_for_response(
json.loads(entity.response_json), originals=originals, mentions=mentions)

if fetch_hfeed:
fetch_hfeed = False # only do it for the first activity
if not source.updates:
source.updates = {}
source.updates = {'last_hfeed_fetch': util.now_fn()}

Source.put_updates(source)

Expand Down
15 changes: 15 additions & 0 deletions original_post_discovery.py
Expand Up @@ -64,6 +64,9 @@ def discover(source, activity, fetch_hfeed=True, include_redirect_sources=True):
Returns: ([string original post URLs], [string mention URLs]) tuple
"""
if not source.updates:
source.updates = {}

originals, mentions = gr_source.Source.original_post_discovery(
activity, domains=source.domains, cache=memcache,
include_redirect_sources=include_redirect_sources,
Expand Down Expand Up @@ -127,10 +130,18 @@ def refetch(source):
Return:
a dict of syndicated_url to a list of new models.SyndicatedPosts
"""
if not source.updates:
source.updates = {}

logging.debug('attempting to refetch h-feed for %s', source.label())
results = {}
for url in _get_author_urls(source):
results.update(_process_author(source, url, refetch=True))

now = util.now_fn()
logging.debug('updating source last_hfeed_fetch %s', now)
source.updates['last_hfeed_fetch'] = now

return results


Expand Down Expand Up @@ -185,6 +196,10 @@ def _posse_post_discovery(source, activity, syndication_url, fetch_hfeed):
results.update(_process_author(source, url))
relationships = results.get(syndication_url, [])

now = util.now_fn()
logging.debug('updating source last_hfeed_fetch %s', now)
source.updates['last_hfeed_fetch'] = util.now_fn()

if not relationships:
# No relationships were found. Remember that we've seen this
# syndicated post to avoid reprocessing it every time
Expand Down
1 change: 0 additions & 1 deletion tasks.py
Expand Up @@ -354,7 +354,6 @@ def strip_likes_shares(objs):
logging.info('Query expired while repropagating responses.', exc_info=True)
else:
raise
source.updates['last_hfeed_fetch'] = source.last_poll_attempt
else:
logging.info(
'skipping refetch h-feed. last-syndication-url %s, last-hfeed-fetch %s',
Expand Down
6 changes: 3 additions & 3 deletions test/test_tasks.py
Expand Up @@ -817,7 +817,7 @@ def _expect_fetch_hfeed(self):

def test_set_last_syndication_url(self):
"""A successful posse-post-discovery round should set
Source.last_syndication_url to approximately the current time.
last_syndication_url and last_hfeed_fetch to approximately the current time.
"""
self.sources[0].domain_urls = ['http://author']
FakeGrSource.DOMAIN = 'source'
Expand All @@ -835,8 +835,8 @@ def test_set_last_syndication_url(self):

# query source
source = self.sources[0].key.get()
self.assertIsNotNone(source)
self.assertIsNotNone(source.last_syndication_url)
self.assertEquals(NOW, source.last_syndication_url)
self.assertEquals(NOW, source.last_hfeed_fetch)

def _setup_refetch_hfeed(self):
self.sources[0].domain_urls = ['http://author']
Expand Down

0 comments on commit 21e37d7

Please sign in to comment.