Save YouTube playlists to library in batch to avoid connection pool starvation
This commit is contained in:
parent
54bf7f1c5b
commit
fcfc45dd70
4 changed files with 63 additions and 1 deletions
|
|
@ -4,6 +4,7 @@ var util = require("../utilities");
|
|||
var InfoGetter = require("../get-info");
|
||||
var db = require("../database");
|
||||
var Media = require("../media");
|
||||
const LOGGER = require('@calzoneman/jsli')('channel/library');
|
||||
|
||||
const TYPE_UNCACHE = {
|
||||
id: "string"
|
||||
|
|
@ -31,6 +32,19 @@ LibraryModule.prototype.cacheMedia = function (media) {
|
|||
}
|
||||
};
|
||||
|
||||
LibraryModule.prototype.cacheMediaList = function (list) {
|
||||
if (this.channel.is(Flags.C_REGISTERED)) {
|
||||
LOGGER.info(
|
||||
'Saving %d items to library for %s',
|
||||
list.length,
|
||||
this.channel.name
|
||||
);
|
||||
db.channels.addListToLibrary(this.channel.name, list).catch(error => {
|
||||
LOGGER.error('Failed to add list to library: %s', error.stack);
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
LibraryModule.prototype.getItem = function (id, cb) {
|
||||
db.channels.getLibraryItem(this.channel.name, id, function (err, row) {
|
||||
if (err) {
|
||||
|
|
|
|||
|
|
@ -592,10 +592,17 @@ PlaylistModule.prototype.queueYouTubePlaylist = function (user, data) {
|
|||
}
|
||||
|
||||
self.channel.refCounter.ref("PlaylistModule::queueYouTubePlaylist");
|
||||
|
||||
if (self.channel.modules.library && data.shouldAddToLibrary) {
|
||||
self.channel.modules.library.cacheMediaList(vids);
|
||||
data.shouldAddToLibrary = false;
|
||||
}
|
||||
|
||||
vids.forEach(function (media) {
|
||||
data.link = util.formatLink(media.id, media.type);
|
||||
self._addItem(media, data, user);
|
||||
});
|
||||
|
||||
self.channel.refCounter.unref("PlaylistModule::queueYouTubePlaylist");
|
||||
|
||||
lock.release();
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue