X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=server%2Flib%2Fschedulers%2Fvideos-redundancy-scheduler.ts;h=91c217615f12d989e2c7722baf1d819eb3005b70;hb=90150006c00fac2f0dea93b28632e654f1becb92;hp=633cbcf6c1f4c26e2a554c24ccf760a344d6e998;hpb=0bae66632a8767f3d5aca080af314bcab56e1889;p=github%2FChocobozzz%2FPeerTube.git diff --git a/server/lib/schedulers/videos-redundancy-scheduler.ts b/server/lib/schedulers/videos-redundancy-scheduler.ts index 633cbcf6c..91c217615 100644 --- a/server/lib/schedulers/videos-redundancy-scheduler.ts +++ b/server/lib/schedulers/videos-redundancy-scheduler.ts @@ -1,7 +1,6 @@ import { move } from 'fs-extra' import { join } from 'path' import { getServerActor } from '@server/models/application/application' -import { TrackerModel } from '@server/models/server/tracker' import { VideoModel } from '@server/models/video/video' import { MStreamingPlaylistFiles, @@ -15,7 +14,7 @@ import { } from '@server/types/models' import { VideosRedundancyStrategy } from '../../../shared/models/redundancy' import { logger, loggerTagsFactory } from '../../helpers/logger' -import { downloadWebTorrentVideo, generateMagnetUri } from '../../helpers/webtorrent' +import { downloadWebTorrentVideo } from '../../helpers/webtorrent' import { CONFIG } from '../../initializers/config' import { HLS_REDUNDANCY_DIRECTORY, REDUNDANCY, VIDEO_IMPORT_TIMEOUT } from '../../initializers/constants' import { VideoRedundancyModel } from '../../models/redundancy/video-redundancy' @@ -116,19 +115,11 @@ export class VideosRedundancyScheduler extends AbstractScheduler { for (const redundancyModel of expired) { try { const redundancyConfig = CONFIG.REDUNDANCY.VIDEOS.STRATEGIES.find(s => s.strategy === redundancyModel.strategy) - const candidate: CandidateToDuplicate = { - redundancy: redundancyConfig, - video: null, - files: [], - streamingPlaylists: [] - } + const { totalUsed } = await VideoRedundancyModel.getStats(redundancyConfig.strategy) // If the administrator disabled the redundancy or decreased the cache size, remove this redundancy instead of extending it - if (!redundancyConfig || await this.isTooHeavy(candidate)) { - logger.info( - 'Destroying redundancy %s because the cache size %s is too heavy.', - redundancyModel.url, redundancyModel.strategy, lTags(candidate.video.uuid) - ) + if (!redundancyConfig || totalUsed > redundancyConfig.size) { + logger.info('Destroying redundancy %s because the cache size %s is too heavy.', redundancyModel.url, redundancyModel.strategy) await removeVideoRedundancy(redundancyModel) } else { @@ -232,10 +223,7 @@ export class VideosRedundancyScheduler extends AbstractScheduler { logger.info('Duplicating %s - %d in videos redundancy with "%s" strategy.', video.url, file.resolution, strategy, lTags(video.uuid)) - const trackerUrls = await TrackerModel.listUrlsByVideoId(video.id) - const magnetUri = generateMagnetUri(video, file, trackerUrls) - - const tmpPath = await downloadWebTorrentVideo({ magnetUri }, VIDEO_IMPORT_TIMEOUT) + const tmpPath = await downloadWebTorrentVideo({ uri: file.torrentUrl }, VIDEO_IMPORT_TIMEOUT) const destPath = join(CONFIG.STORAGE.REDUNDANCY_DIR, file.filename) await move(tmpPath, destPath, { overwrite: true }) @@ -364,7 +352,7 @@ export class VideosRedundancyScheduler extends AbstractScheduler { // We need more attributes and check if the video still exists const getVideoOptions = { videoObject: videoUrl, - syncParam: { likes: false, dislikes: false, shares: false, comments: false, thumbnail: false, refreshVideo: true }, + syncParam: { rates: false, shares: false, comments: false, thumbnail: false, refreshVideo: true }, fetchType: 'all' as 'all' } const { video } = await getOrCreateAPVideo(getVideoOptions)