]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/commitdiff
Little SQL optimization
authorChocobozzz <me@florianbigard.com>
Thu, 11 Jan 2018 13:30:27 +0000 (14:30 +0100)
committerChocobozzz <me@florianbigard.com>
Thu, 11 Jan 2018 13:30:27 +0000 (14:30 +0100)
server/models/video/video.ts

index 6b825bf931f39dc6141bec8249a23881c2a2dca3..391568df43bf0d4a4e3082eb4437286c60e00e4e 100644 (file)
@@ -94,15 +94,25 @@ enum ScopeNames {
   [ScopeNames.WITH_ACCOUNT_DETAILS]: {
     include: [
       {
-        model: () => VideoChannelModel,
+        model: () => VideoChannelModel.unscoped(),
         required: true,
         include: [
+          {
+            attributes: {
+              exclude: [ 'privateKey', 'publicKey' ]
+            },
+            model: () => ActorModel,
+            required: true
+          },
           {
             model: () => AccountModel,
             required: true,
             include: [
               {
                 model: () => ActorModel,
+                attributes: {
+                  exclude: [ 'privateKey', 'publicKey' ]
+                },
                 required: true,
                 include: [
                   {
@@ -511,22 +521,6 @@ export class VideoModel extends Model<VideoModel> {
     return VideoModel.findById(id)
   }
 
-  static loadAndPopulateAccount (id: number) {
-    return VideoModel.scope([ ScopeNames.WITH_ACCOUNT_DETAILS ]).findById(id)
-  }
-
-  static loadByUrl (url: string, t?: Sequelize.Transaction) {
-    const query: IFindOptions<VideoModel> = {
-      where: {
-        url
-      }
-    }
-
-    if (t !== undefined) query.transaction = t
-
-    return VideoModel.findOne(query)
-  }
-
   static loadByUrlAndPopulateAccount (url: string, t?: Sequelize.Transaction) {
     const query: IFindOptions<VideoModel> = {
       where: {