Ignore library cached metadata when queueing
The use of the channel library as a cache for metadata to avoid
re-requesting metadata for known media is an optimization that dates
back to 1.0. However, it doesn't have any TTL, is prone to bugs, and is
of dubious value.
This commit ignores the results of the library check when queueing a new
video, opting to always re-request the metadata. This fixes a few bugs:
* Google Drive metadata being lost when storing in library
* Streamable metadata being lost when storing in library
* Videos in the channel library that are now unavailable on their
source website being queueable and then failing to play (e.g. deleted
YouTube videos).
In its place, a small fail-open check is left behind to emit metric
counters on how many queues would have been cache-hits, to provide
insight into whether a proper caching solution (i.e. one not tacked on
top of the library) would be worth pursuing or not. This will be
removed eventually.
This commit is contained in:
parent
b7ceee8ef4
commit
c152a19624
|
|
@ -2,7 +2,7 @@
|
||||||
"author": "Calvin Montgomery",
|
"author": "Calvin Montgomery",
|
||||||
"name": "CyTube",
|
"name": "CyTube",
|
||||||
"description": "Online media synchronizer and chat",
|
"description": "Online media synchronizer and chat",
|
||||||
"version": "3.39.6",
|
"version": "3.40.0",
|
||||||
"repository": {
|
"repository": {
|
||||||
"url": "http://github.com/calzoneman/sync"
|
"url": "http://github.com/calzoneman/sync"
|
||||||
},
|
},
|
||||||
|
|
|
||||||
|
|
@ -8,6 +8,7 @@ var Flags = require("../flags");
|
||||||
var db = require("../database");
|
var db = require("../database");
|
||||||
var CustomEmbedFilter = require("../customembed").filter;
|
var CustomEmbedFilter = require("../customembed").filter;
|
||||||
var XSS = require("../xss");
|
var XSS = require("../xss");
|
||||||
|
import counters from '../counters';
|
||||||
|
|
||||||
const LOGGER = require('@calzoneman/jsli')('playlist');
|
const LOGGER = require('@calzoneman/jsli')('playlist');
|
||||||
|
|
||||||
|
|
@ -328,6 +329,10 @@ PlaylistModule.prototype.handleQueue = function (user, data) {
|
||||||
|
|
||||||
var id = data.id;
|
var id = data.id;
|
||||||
var type = data.type;
|
var type = data.type;
|
||||||
|
if (type === "lib") {
|
||||||
|
LOGGER.warn("Outdated client: IP %s emitting queue with type=lib",
|
||||||
|
user.realip);
|
||||||
|
}
|
||||||
|
|
||||||
if (data.pos !== "next" && data.pos !== "end") {
|
if (data.pos !== "next" && data.pos !== "end") {
|
||||||
return;
|
return;
|
||||||
|
|
@ -450,36 +455,25 @@ PlaylistModule.prototype.queueStandard = function (user, data) {
|
||||||
|
|
||||||
const self = this;
|
const self = this;
|
||||||
this.channel.refCounter.ref("PlaylistModule::queueStandard");
|
this.channel.refCounter.ref("PlaylistModule::queueStandard");
|
||||||
|
counters.add("playlist:queue:count", 1);
|
||||||
this.semaphore.queue(function (lock) {
|
this.semaphore.queue(function (lock) {
|
||||||
var lib = self.channel.modules.library;
|
var lib = self.channel.modules.library;
|
||||||
if (lib && self.channel.is(Flags.C_REGISTERED) && !util.isLive(data.type)) {
|
if (lib && self.channel.is(Flags.C_REGISTERED) && !util.isLive(data.type)) {
|
||||||
|
// TODO: remove this check entirely once metrics are collected.
|
||||||
lib.getItem(data.id, function (err, item) {
|
lib.getItem(data.id, function (err, item) {
|
||||||
if (err && err !== "Item not in library") {
|
if (err && err !== "Item not in library") {
|
||||||
error(err+"");
|
LOGGER.error("Failed to query for library item: %s", String(err));
|
||||||
self.channel.refCounter.unref("PlaylistModule::queueStandard");
|
} else if (err === "Item not in library") {
|
||||||
return lock.release();
|
counters.add("playlist:queue:library:miss", 1);
|
||||||
}
|
|
||||||
|
|
||||||
// YouTube livestreams transition to becoming regular videos,
|
|
||||||
// breaking the cached duration of 0.
|
|
||||||
// In the future, the media cache should be decoupled from
|
|
||||||
// the library and this will no longer be an issue, but for now
|
|
||||||
// treat 0-length yt library entries as non-existent.
|
|
||||||
if (item !== null && item.type === "yt" && item.seconds === 0) {
|
|
||||||
data.type = "yt"; // Kludge -- library queue has type: "lib"
|
|
||||||
item = null;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (item !== null) {
|
|
||||||
/* Don't re-cache data we got from the library */
|
|
||||||
data.shouldAddToLibrary = false;
|
|
||||||
self._addItem(item, data, user, function () {
|
|
||||||
lock.release();
|
|
||||||
self.channel.refCounter.unref("PlaylistModule::queueStandard");
|
|
||||||
});
|
|
||||||
} else {
|
} else {
|
||||||
handleLookup();
|
// temp hack until all clients are updated.
|
||||||
|
// previously, library search results would queue with
|
||||||
|
// type "lib"; this has now been changed.
|
||||||
|
data.type = item.type;
|
||||||
|
counters.add("playlist:queue:library:hit", 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
handleLookup();
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
handleLookup();
|
handleLookup();
|
||||||
|
|
|
||||||
|
|
@ -431,7 +431,8 @@ module.exports = {
|
||||||
bitrate: media.meta.bitrate,
|
bitrate: media.meta.bitrate,
|
||||||
codec: media.meta.codec,
|
codec: media.meta.codec,
|
||||||
scuri: media.meta.scuri,
|
scuri: media.meta.scuri,
|
||||||
embed: media.meta.embed
|
embed: media.meta.embed,
|
||||||
|
direct: media.meta.direct
|
||||||
});
|
});
|
||||||
|
|
||||||
db.query("INSERT INTO `channel_libraries` " +
|
db.query("INSERT INTO `channel_libraries` " +
|
||||||
|
|
|
||||||
|
|
@ -879,7 +879,7 @@ Callbacks = {
|
||||||
generator: function (item, page, index) {
|
generator: function (item, page, index) {
|
||||||
var li = makeSearchEntry(item, false);
|
var li = makeSearchEntry(item, false);
|
||||||
if(hasPermission("playlistadd") || hasPermission("deletefromchannellib")) {
|
if(hasPermission("playlistadd") || hasPermission("deletefromchannellib")) {
|
||||||
addLibraryButtons(li, item.id, data.source);
|
addLibraryButtons(li, item, data.source);
|
||||||
}
|
}
|
||||||
$(li).appendTo($("#library"));
|
$(li).appendTo($("#library"));
|
||||||
},
|
},
|
||||||
|
|
|
||||||
|
|
@ -1084,12 +1084,13 @@ function clearSearchResults() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function addLibraryButtons(li, id, source) {
|
function addLibraryButtons(li, item, source) {
|
||||||
var btns = $("<div/>").addClass("btn-group")
|
var btns = $("<div/>").addClass("btn-group")
|
||||||
.addClass("pull-left")
|
.addClass("pull-left")
|
||||||
.prependTo(li);
|
.prependTo(li);
|
||||||
|
|
||||||
var type = (source === "library") ? "lib" : source;
|
var id = item.id;
|
||||||
|
var type = item.type;
|
||||||
|
|
||||||
if(hasPermission("playlistadd")) {
|
if(hasPermission("playlistadd")) {
|
||||||
if(hasPermission("playlistnext")) {
|
if(hasPermission("playlistnext")) {
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue