aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/models/video
diff options
context:
space:
mode:
Diffstat (limited to 'server/models/video')
-rw-r--r--server/models/video/video-file.ts9
-rw-r--r--server/models/video/video-streaming-playlist.ts16
2 files changed, 23 insertions, 2 deletions
diff --git a/server/models/video/video-file.ts b/server/models/video/video-file.ts
index fa5a6e76d..e08999385 100644
--- a/server/models/video/video-file.ts
+++ b/server/models/video/video-file.ts
@@ -24,9 +24,10 @@ import { VideoModel } from './video'
24import { VideoRedundancyModel } from '../redundancy/video-redundancy' 24import { VideoRedundancyModel } from '../redundancy/video-redundancy'
25import { VideoStreamingPlaylistModel } from './video-streaming-playlist' 25import { VideoStreamingPlaylistModel } from './video-streaming-playlist'
26import { FindOptions, Op, QueryTypes, Transaction } from 'sequelize' 26import { FindOptions, Op, QueryTypes, Transaction } from 'sequelize'
27import { MIMETYPES } from '../../initializers/constants' 27import { MIMETYPES, MEMOIZE_LENGTH, MEMOIZE_TTL } from '../../initializers/constants'
28import { MVideoFile, MVideoFileStreamingPlaylistVideo, MVideoFileVideo } from '../../typings/models/video/video-file' 28import { MVideoFile, MVideoFileStreamingPlaylistVideo, MVideoFileVideo } from '../../typings/models/video/video-file'
29import { MStreamingPlaylistVideo, MVideo } from '@server/typings/models' 29import { MStreamingPlaylistVideo, MVideo } from '@server/typings/models'
30import * as memoizee from 'memoizee'
30 31
31@Table({ 32@Table({
32 tableName: 'videoFile', 33 tableName: 'videoFile',
@@ -138,6 +139,12 @@ export class VideoFileModel extends Model<VideoFileModel> {
138 }) 139 })
139 RedundancyVideos: VideoRedundancyModel[] 140 RedundancyVideos: VideoRedundancyModel[]
140 141
142 static doesInfohashExistCached = memoizee(VideoFileModel.doesInfohashExist, {
143 promise: true,
144 max: MEMOIZE_LENGTH.INFO_HASH_EXISTS,
145 maxAge: MEMOIZE_TTL.INFO_HASH_EXISTS
146 })
147
141 static doesInfohashExist (infoHash: string) { 148 static doesInfohashExist (infoHash: string) {
142 const query = 'SELECT 1 FROM "videoFile" WHERE "infoHash" = $infoHash LIMIT 1' 149 const query = 'SELECT 1 FROM "videoFile" WHERE "infoHash" = $infoHash LIMIT 1'
143 const options = { 150 const options = {
diff --git a/server/models/video/video-streaming-playlist.ts b/server/models/video/video-streaming-playlist.ts
index faad4cc2d..0099add4e 100644
--- a/server/models/video/video-streaming-playlist.ts
+++ b/server/models/video/video-streaming-playlist.ts
@@ -5,7 +5,14 @@ import { VideoModel } from './video'
5import { VideoRedundancyModel } from '../redundancy/video-redundancy' 5import { VideoRedundancyModel } from '../redundancy/video-redundancy'
6import { VideoStreamingPlaylistType } from '../../../shared/models/videos/video-streaming-playlist.type' 6import { VideoStreamingPlaylistType } from '../../../shared/models/videos/video-streaming-playlist.type'
7import { isActivityPubUrlValid } from '../../helpers/custom-validators/activitypub/misc' 7import { isActivityPubUrlValid } from '../../helpers/custom-validators/activitypub/misc'
8import { CONSTRAINTS_FIELDS, P2P_MEDIA_LOADER_PEER_VERSION, STATIC_DOWNLOAD_PATHS, STATIC_PATHS } from '../../initializers/constants' 8import {
9 CONSTRAINTS_FIELDS,
10 MEMOIZE_LENGTH,
11 MEMOIZE_TTL,
12 P2P_MEDIA_LOADER_PEER_VERSION,
13 STATIC_DOWNLOAD_PATHS,
14 STATIC_PATHS
15} from '../../initializers/constants'
9import { join } from 'path' 16import { join } from 'path'
10import { sha1 } from '../../helpers/core-utils' 17import { sha1 } from '../../helpers/core-utils'
11import { isArrayOf } from '../../helpers/custom-validators/misc' 18import { isArrayOf } from '../../helpers/custom-validators/misc'
@@ -13,6 +20,7 @@ import { Op, QueryTypes } from 'sequelize'
13import { MStreamingPlaylist, MVideoFile } from '@server/typings/models' 20import { MStreamingPlaylist, MVideoFile } from '@server/typings/models'
14import { VideoFileModel } from '@server/models/video/video-file' 21import { VideoFileModel } from '@server/models/video/video-file'
15import { getTorrentFileName, getVideoFilename } from '@server/lib/video-paths' 22import { getTorrentFileName, getVideoFilename } from '@server/lib/video-paths'
23import * as memoizee from 'memoizee'
16 24
17@Table({ 25@Table({
18 tableName: 'videoStreamingPlaylist', 26 tableName: 'videoStreamingPlaylist',
@@ -89,6 +97,12 @@ export class VideoStreamingPlaylistModel extends Model<VideoStreamingPlaylistMod
89 }) 97 })
90 RedundancyVideos: VideoRedundancyModel[] 98 RedundancyVideos: VideoRedundancyModel[]
91 99
100 static doesInfohashExistCached = memoizee(VideoStreamingPlaylistModel.doesInfohashExist, {
101 promise: true,
102 max: MEMOIZE_LENGTH.INFO_HASH_EXISTS,
103 maxAge: MEMOIZE_TTL.INFO_HASH_EXISTS
104 })
105
92 static doesInfohashExist (infoHash: string) { 106 static doesInfohashExist (infoHash: string) {
93 const query = 'SELECT 1 FROM "videoStreamingPlaylist" WHERE $infoHash = ANY("p2pMediaLoaderInfohashes") LIMIT 1' 107 const query = 'SELECT 1 FROM "videoStreamingPlaylist" WHERE $infoHash = ANY("p2pMediaLoaderInfohashes") LIMIT 1'
94 const options = { 108 const options = {