From 3fb13fa7fc328f333936467abb810d58843e34e2 Mon Sep 17 00:00:00 2001 From: fankom Date: Wed, 24 Jan 2018 10:34:35 -0800 Subject: [PATCH 1/4] Fixing issue with too many calls to admin-ajax. - Added validation before attachment_id gets added to array. --- js/src/scraper/scraper.gallery.js | 5 +++++ js/src/scraper/scraper.image.js | 5 +++++ js/yoast-acf-analysis.js | 10 ++++++++++ 3 files changed, 20 insertions(+) diff --git a/js/src/scraper/scraper.gallery.js b/js/src/scraper/scraper.gallery.js index fa2a9500..7c7dac34 100644 --- a/js/src/scraper/scraper.gallery.js +++ b/js/src/scraper/scraper.gallery.js @@ -18,6 +18,11 @@ Scraper.prototype.scrape = function( fields ) { // TODO: Is this the best way to get the attachment id? var attachment_id = jQuery( this ).val(); + // Skip if attachment id is empty + if( attachment_id === '' || typeof attachment_id === 'undefined' ){ + return; + } + // Collect all attachment ids for cache refresh attachment_ids.push( attachment_id ); diff --git a/js/src/scraper/scraper.image.js b/js/src/scraper/scraper.image.js index 3bf7c993..559b9365 100644 --- a/js/src/scraper/scraper.image.js +++ b/js/src/scraper/scraper.image.js @@ -16,6 +16,11 @@ Scraper.prototype.scrape = function( fields ) { var attachment_id = field.$el.find( "input[type=hidden]" ).val(); + // Skip if attachment id is empty + if( attachment_id === '' || typeof attachment_id === 'undefined' ){ + return field; + } + attachment_ids.push( attachment_id ); if ( attachmentCache.get( attachment_id, "attachment" ) ) { diff --git a/js/yoast-acf-analysis.js b/js/yoast-acf-analysis.js index 0c344d96..32aae538 100644 --- a/js/yoast-acf-analysis.js +++ b/js/yoast-acf-analysis.js @@ -569,6 +569,11 @@ Scraper.prototype.scrape = function( fields ) { // TODO: Is this the best way to get the attachment id? var attachment_id = jQuery( this ).val(); + // Skip if attachment id is empty + if( attachment_id === '' || typeof attachment_id === 'undefined' ){ + return; + } + // Collect all attachment ids for cache refresh attachment_ids.push( attachment_id ); @@ -609,6 +614,11 @@ Scraper.prototype.scrape = function( fields ) { var attachment_id = field.$el.find( "input[type=hidden]" ).val(); + // Skip if attachment id is empty + if( attachment_id === '' || typeof attachment_id === 'undefined' ){ + return field; + } + attachment_ids.push( attachment_id ); if ( attachmentCache.get( attachment_id, "attachment" ) ) { From ca4636f900f89e6ca99bd17639002714e46f79dc Mon Sep 17 00:00:00 2001 From: fankom Date: Wed, 24 Jan 2018 11:27:57 -0800 Subject: [PATCH 2/4] Fixing eslint errors. --- js/src/scraper/scraper.gallery.js | 2 +- js/src/scraper/scraper.image.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/js/src/scraper/scraper.gallery.js b/js/src/scraper/scraper.gallery.js index 7c7dac34..81d371eb 100644 --- a/js/src/scraper/scraper.gallery.js +++ b/js/src/scraper/scraper.gallery.js @@ -19,7 +19,7 @@ Scraper.prototype.scrape = function( fields ) { var attachment_id = jQuery( this ).val(); // Skip if attachment id is empty - if( attachment_id === '' || typeof attachment_id === 'undefined' ){ + if ( attachment_id === "" || typeof attachment_id === "undefined" ) { return; } diff --git a/js/src/scraper/scraper.image.js b/js/src/scraper/scraper.image.js index 559b9365..b148cef9 100644 --- a/js/src/scraper/scraper.image.js +++ b/js/src/scraper/scraper.image.js @@ -17,7 +17,7 @@ Scraper.prototype.scrape = function( fields ) { var attachment_id = field.$el.find( "input[type=hidden]" ).val(); // Skip if attachment id is empty - if( attachment_id === '' || typeof attachment_id === 'undefined' ){ + if ( attachment_id === "" || typeof attachment_id === "undefined" ) { return field; } From 34de5bc3c1cc0a1cab201a686095c926759ced70 Mon Sep 17 00:00:00 2001 From: fankom Date: Wed, 24 Jan 2018 11:41:16 -0800 Subject: [PATCH 3/4] Fixing eslint errors. --- js/yoast-acf-analysis.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/js/yoast-acf-analysis.js b/js/yoast-acf-analysis.js index 32aae538..2258f7b2 100644 --- a/js/yoast-acf-analysis.js +++ b/js/yoast-acf-analysis.js @@ -570,7 +570,7 @@ Scraper.prototype.scrape = function( fields ) { var attachment_id = jQuery( this ).val(); // Skip if attachment id is empty - if( attachment_id === '' || typeof attachment_id === 'undefined' ){ + if ( attachment_id === "" || typeof attachment_id === "undefined" ) { return; } @@ -615,7 +615,7 @@ Scraper.prototype.scrape = function( fields ) { var attachment_id = field.$el.find( "input[type=hidden]" ).val(); // Skip if attachment id is empty - if( attachment_id === '' || typeof attachment_id === 'undefined' ){ + if ( attachment_id === "" || typeof attachment_id === "undefined" ) { return field; } From 92c98b840c342aaafa7456621f01042b6573a2b2 Mon Sep 17 00:00:00 2001 From: Frank Molina Date: Thu, 15 Feb 2018 14:58:12 -0800 Subject: [PATCH 4/4] Changed check to the cache level in refresh function. --- js/src/cache/cache.attachments.js | 7 ++++++- js/src/scraper/scraper.gallery.js | 5 ----- js/src/scraper/scraper.image.js | 5 ----- js/yoast-acf-analysis.js | 17 ++++++----------- 4 files changed, 12 insertions(+), 22 deletions(-) diff --git a/js/src/cache/cache.attachments.js b/js/src/cache/cache.attachments.js index dffcd95b..b3ff8ec9 100644 --- a/js/src/cache/cache.attachments.js +++ b/js/src/cache/cache.attachments.js @@ -2,7 +2,12 @@ var cache = require( "./cache.js" ); var refresh = function( attachment_ids ) { - var uncached = cache.getUncached( attachment_ids, "attachment" ); + + attachment_ids = attachment_ids.filter( function (id) { + return id !== "" && typeof id !== "undefined" + }); + + var uncached = cache.getUncached( attachment_ids, "attachment" ); if ( uncached.length === 0 ) { return; diff --git a/js/src/scraper/scraper.gallery.js b/js/src/scraper/scraper.gallery.js index 81d371eb..fa2a9500 100644 --- a/js/src/scraper/scraper.gallery.js +++ b/js/src/scraper/scraper.gallery.js @@ -18,11 +18,6 @@ Scraper.prototype.scrape = function( fields ) { // TODO: Is this the best way to get the attachment id? var attachment_id = jQuery( this ).val(); - // Skip if attachment id is empty - if ( attachment_id === "" || typeof attachment_id === "undefined" ) { - return; - } - // Collect all attachment ids for cache refresh attachment_ids.push( attachment_id ); diff --git a/js/src/scraper/scraper.image.js b/js/src/scraper/scraper.image.js index b148cef9..3bf7c993 100644 --- a/js/src/scraper/scraper.image.js +++ b/js/src/scraper/scraper.image.js @@ -16,11 +16,6 @@ Scraper.prototype.scrape = function( fields ) { var attachment_id = field.$el.find( "input[type=hidden]" ).val(); - // Skip if attachment id is empty - if ( attachment_id === "" || typeof attachment_id === "undefined" ) { - return field; - } - attachment_ids.push( attachment_id ); if ( attachmentCache.get( attachment_id, "attachment" ) ) { diff --git a/js/yoast-acf-analysis.js b/js/yoast-acf-analysis.js index 2258f7b2..5a613a90 100644 --- a/js/yoast-acf-analysis.js +++ b/js/yoast-acf-analysis.js @@ -92,7 +92,12 @@ module.exports = App; var cache = require( "./cache.js" ); var refresh = function( attachment_ids ) { - var uncached = cache.getUncached( attachment_ids, "attachment" ); + + attachment_ids = attachment_ids.filter( function (id) { + return id !== "" && typeof id !== "undefined" + }); + + var uncached = cache.getUncached( attachment_ids, "attachment" ); if ( uncached.length === 0 ) { return; @@ -569,11 +574,6 @@ Scraper.prototype.scrape = function( fields ) { // TODO: Is this the best way to get the attachment id? var attachment_id = jQuery( this ).val(); - // Skip if attachment id is empty - if ( attachment_id === "" || typeof attachment_id === "undefined" ) { - return; - } - // Collect all attachment ids for cache refresh attachment_ids.push( attachment_id ); @@ -614,11 +614,6 @@ Scraper.prototype.scrape = function( fields ) { var attachment_id = field.$el.find( "input[type=hidden]" ).val(); - // Skip if attachment id is empty - if ( attachment_id === "" || typeof attachment_id === "undefined" ) { - return field; - } - attachment_ids.push( attachment_id ); if ( attachmentCache.get( attachment_id, "attachment" ) ) {