From 91f9987d41526829b95fd3d72443e86b338aafb8 Mon Sep 17 00:00:00 2001 From: Joseph Schorr Date: Mon, 19 May 2014 12:35:16 -0400 Subject: [PATCH 1/3] Fix NPE --- static/js/app.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/static/js/app.js b/static/js/app.js index 9c701d62a..0ecbb8842 100644 --- a/static/js/app.js +++ b/static/js/app.js @@ -3789,6 +3789,8 @@ quayApp.directive('setupTriggerDialog', function () { var modalSetup = false; $scope.show = function() { + if (!$scope.trigger || !$scope.repository) { return; } + $scope.activating = false; $scope.pullEntity = null; $scope.publicPull = true; @@ -3798,7 +3800,7 @@ quayApp.directive('setupTriggerDialog', function () { if (!modalSetup) { $('#setupTriggerModal').on('hidden.bs.modal', function () { - if ($scope.trigger['is_active']) { return; } + if (!$scope.trigger || $scope.trigger['is_active']) { return; } $scope.$apply(function() { $scope.cancelSetupTrigger(); From 1c0c551d0010057d2b60ee04b437149464aa0366 Mon Sep 17 00:00:00 2001 From: Joseph Schorr Date: Mon, 19 May 2014 13:11:07 -0400 Subject: [PATCH 2/3] Add better logging to the snapshot generator for timing purposes and make sure the PhantomJS script always exists after a maximum of 10 seconds. --- util/phantomjs-runner.js | 62 ++++++++++++++++++++++++++-------------- util/seo.py | 6 +++- 2 files changed, 45 insertions(+), 23 deletions(-) diff --git a/util/phantomjs-runner.js b/util/phantomjs-runner.js index 30b0439fa..fae6496e0 100644 --- a/util/phantomjs-runner.js +++ b/util/phantomjs-runner.js @@ -1,37 +1,55 @@ var system = require('system'); var url = system.args[1] || ''; +var count = 0; + if(url.length > 0) { var page = require('webpage').create(); page.open(url, function (status) { - if (status == 'success') { - var delay, checker = (function() { - var html = page.evaluate(function () { - var found = document.getElementsByTagName('html')[0].outerHTML || ''; - if (window.__isLoading && !window.__isLoading()) { - return found; - } - if (found.indexOf('404 Not Found') > 0) { - return found; - } - return null; - }); + try { + if (status == 'success') { + var delay; + var checker = (function() { + count++; - if (html) { - if (html.indexOf('404 Not Found') > 0) { + if (count > 100) { console.log('Not Found'); phantom.exit(); - return; + return null; } - clearTimeout(delay); - console.log(html); - phantom.exit(); - } - }); - delay = setInterval(checker, 100); - } else { + var html = page.evaluate(function () { + var found = document.getElementsByTagName('html')[0].outerHTML || ''; + if (window.__isLoading && !window.__isLoading()) { + return found; + } + if (found.indexOf('404 Not Found') > 0) { + return found; + } + return null; + }); + + if (html) { + if (html.indexOf('404 Not Found') > 0) { + console.log('Not Found'); + phantom.exit(); + return; + } + + clearTimeout(delay); + console.log(html); + phantom.exit(); + } + }); + delay = setInterval(checker, 100); + } else { + console.log('Not Found'); + phantom.exit(); + } + } catch (e) { console.log('Not Found'); phantom.exit(); } }); +} else { + phantom.exit(); } \ No newline at end of file diff --git a/util/seo.py b/util/seo.py index 42af53502..8a88b0e05 100644 --- a/util/seo.py +++ b/util/seo.py @@ -3,12 +3,12 @@ import logging from bs4 import BeautifulSoup - logger = logging.getLogger(__name__) def render_snapshot(url): logger.info('Snapshotting url: %s' % url) + out_html = subprocess.check_output(['phantomjs', '--ignore-ssl-errors=yes', 'util/phantomjs-runner.js', url]) @@ -16,9 +16,13 @@ def render_snapshot(url): return None # Remove script tags + logger.info('Removing script tags: %s' % url) + soup = BeautifulSoup(out_html.decode('utf8')) to_extract = soup.findAll('script') for item in to_extract: item.extract() + logger.info('Snapshotted url: %s' % url) + return str(soup) From cbcff2adeeb42222f2529ea3603b6f68935090c4 Mon Sep 17 00:00:00 2001 From: Joseph Schorr Date: Mon, 19 May 2014 13:18:37 -0400 Subject: [PATCH 3/3] Make Phantomjs use a disk cache for the snapshots --- util/seo.py | 1 + 1 file changed, 1 insertion(+) diff --git a/util/seo.py b/util/seo.py index 8a88b0e05..b75480661 100644 --- a/util/seo.py +++ b/util/seo.py @@ -10,6 +10,7 @@ def render_snapshot(url): logger.info('Snapshotting url: %s' % url) out_html = subprocess.check_output(['phantomjs', '--ignore-ssl-errors=yes', + '--disk-cache=yes', 'util/phantomjs-runner.js', url]) if not out_html or out_html.strip() == 'Not Found':