Permalink
Browse files

ux: fetch/set editor titles only when in foreground

Saves batter/provides a performance boost
with huuge playlists playing in background tab
with opened editor.
  • Loading branch information...
lidel committed Jan 7, 2018
1 parent 54d6c55 commit d7ae8a1f0eb4ef28c224b0f7405ade104e9d841b
Showing with 15 additions and 5 deletions.
  1. +5 −1 pls.watch.editor.js
  2. +10 −4 pls.watch.js
View
@@ -95,7 +95,11 @@ function Editor(Playlist, Player) { // eslint-disable-line no-unused-vars
intervalLink.attr('data-interval-uri', intervalLink.text());
if (interval.urlKey === 'v' && !isExternalURI(interval.videoId)) {
Editor._createAsyncVideoTitle(interval.videoId, intervalLink);
// fetch/set editor titles only when in foreground
// (great performance boost for huuge playlists playing in background)
window.requestAnimationFrame(function() {
Editor._createAsyncVideoTitle(interval.videoId, intervalLink);
});
}
return intervalLink;
View
@@ -23,17 +23,17 @@ function logLady(a, b) { // kek
: a);
}
// Limit concurrent jQuery ajax requests to at most 2 at a time, and queue the rest.
// Limit concurrent jQuery ajax requests to at most 3 at a time, and queue the rest.
// Credit: https://gist.github.com/OllieTerrance/158a4c436baa64c4324803467844b00f
var ajaxQueue = [];
var ajaxActive = 0;
var ajaxMaxConc = 2;
var ajaxMaxConc = 3;
$.queuedAjax = function(obj) {
var oldSuccess = obj.success;
var oldError = obj.error;
var callback = function() {
if (ajaxActive === ajaxMaxConc) {
window.requestAnimationFrame(function() { $.ajax(ajaxQueue.shift()); });
window.setTimeout(function() { $.ajax(ajaxQueue.shift()); }, 25);
} else {
ajaxActive--;
}
@@ -50,7 +50,7 @@ $.queuedAjax = function(obj) {
ajaxQueue.push(obj);
} else {
ajaxActive++;
window.requestAnimationFrame(function() { $.ajax(obj); });
window.setTimeout(function() { $.ajax(obj); }, 25);
}
};
@@ -1260,10 +1260,16 @@ function setCachedTitle(id) {
}
function readTitleFromCache(id) {
if (typeof (sessionStorage) === 'undefined') {
return null;
}
return window.sessionStorage.getItem(titleCacheKey(id));
}
function addTitleToCache(id, title) {
if (typeof (sessionStorage) === 'undefined') {
return;
}
window.sessionStorage.setItem(titleCacheKey(id), title);
}

0 comments on commit d7ae8a1

Please sign in to comment.