]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - server/models/video/video.ts
Merge remote-tracking branch 'weblate/develop' into develop
[github/Chocobozzz/PeerTube.git] / server / models / video / video.ts
index 9e02d163f5f52ddf3b39f962ac7fdd8639d3800e..5964526a997061c2503d361043d77935e10dc40b 100644 (file)
@@ -145,6 +145,7 @@ export enum ScopeNames {
   WITH_USER_HISTORY = 'WITH_USER_HISTORY',
   WITH_STREAMING_PLAYLISTS = 'WITH_STREAMING_PLAYLISTS',
   WITH_USER_ID = 'WITH_USER_ID',
+  WITH_IMMUTABLE_ATTRIBUTES = 'WITH_IMMUTABLE_ATTRIBUTES',
   WITH_THUMBNAILS = 'WITH_THUMBNAILS'
 }
 
@@ -188,6 +189,9 @@ export type AvailableForListIDsOptions = {
 }
 
 @Scopes(() => ({
+  [ScopeNames.WITH_IMMUTABLE_ATTRIBUTES]: {
+    attributes: [ 'id', 'url', 'uuid', 'remote' ]
+  },
   [ScopeNames.FOR_API]: (options: ForAPIOptions) => {
     const query: FindOptions = {
       include: [
@@ -1476,20 +1480,16 @@ export class VideoModel extends Model<VideoModel> {
 
   static loadImmutableAttributes (id: number | string, t?: Transaction): Bluebird<MVideoImmutable> {
     const fun = () => {
-      const where = buildWhereIdOrUUID(id)
-      const options = {
-        attributes: [
-          'id', 'url', 'uuid'
-        ],
-        where,
+      const query = {
+        where: buildWhereIdOrUUID(id),
         transaction: t
       }
 
-      return VideoModel.unscoped().findOne(options)
+      return VideoModel.scope(ScopeNames.WITH_IMMUTABLE_ATTRIBUTES).findOne(query)
     }
 
     return ModelCache.Instance.doCache({
-      cacheType: 'video-immutable',
+      cacheType: 'load-video-immutable-id',
       key: '' + id,
       deleteKey: 'video',
       fun
@@ -1559,6 +1559,26 @@ export class VideoModel extends Model<VideoModel> {
     return VideoModel.scope(ScopeNames.WITH_THUMBNAILS).findOne(query)
   }
 
+  static loadByUrlImmutableAttributes (url: string, transaction?: Transaction): Bluebird<MVideoImmutable> {
+    const fun = () => {
+      const query: FindOptions = {
+        where: {
+          url
+        },
+        transaction
+      }
+
+      return VideoModel.scope(ScopeNames.WITH_IMMUTABLE_ATTRIBUTES).findOne(query)
+    }
+
+    return ModelCache.Instance.doCache({
+      cacheType: 'load-video-immutable-url',
+      key: url,
+      deleteKey: 'video',
+      fun
+    })
+  }
+
   static loadByUrlAndPopulateAccount (url: string, transaction?: Transaction): Bluebird<MVideoAccountLightBlacklistAllFiles> {
     const query: FindOptions = {
       where: {