aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/models/video/video-file.ts
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2020-01-03 13:47:45 +0100
committerChocobozzz <me@florianbigard.com>2020-01-03 13:47:45 +0100
commit35f28e94c763370616d25d5820f4b9ef70cedca9 (patch)
tree7ade51d5e60a5856d74c5776dd62fcaaa3ae0858 /server/models/video/video-file.ts
parent562724a1ed13fe93aba08ca1a0f8e029819e9f32 (diff)
downloadPeerTube-35f28e94c763370616d25d5820f4b9ef70cedca9.tar.gz
PeerTube-35f28e94c763370616d25d5820f4b9ef70cedca9.tar.zst
PeerTube-35f28e94c763370616d25d5820f4b9ef70cedca9.zip
Add infohash cache
Diffstat (limited to 'server/models/video/video-file.ts')
-rw-r--r--server/models/video/video-file.ts9
1 files changed, 8 insertions, 1 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 = {