]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - server/models/application/application.ts
Optimize video view AP processing
[github/Chocobozzz/PeerTube.git] / server / models / application / application.ts
index f3c0f1052735c2749110a0c7bf2296086763fa84..854a5fb368550b4744fa194637c9f1631f1ab2a8 100644 (file)
@@ -1,6 +1,14 @@
-import { Transaction } from 'sequelize'
-import { AllowNull, Column, Default, IsInt, Model, Table } from 'sequelize-typescript'
+import { AllowNull, Column, Default, DefaultScope, HasOne, IsInt, Model, Table } from 'sequelize-typescript'
+import { AccountModel } from '../account/account'
 
+@DefaultScope({
+  include: [
+    {
+      model: () => AccountModel,
+      required: true
+    }
+  ]
+})
 @Table({
   tableName: 'application'
 })
@@ -12,24 +20,19 @@ export class ApplicationModel extends Model<ApplicationModel> {
   @Column
   migrationVersion: number
 
+  @HasOne(() => AccountModel, {
+    foreignKey: {
+      allowNull: true
+    },
+    onDelete: 'cascade'
+  })
+  Account: AccountModel
+
   static countTotal () {
     return ApplicationModel.count()
   }
 
-  static loadMigrationVersion () {
-    const query = {
-      attributes: [ 'migrationVersion' ]
-    }
-
-    return ApplicationModel.findOne(query).then(data => data ? data.migrationVersion : null)
-  }
-
-  static updateMigrationVersion (newVersion: number, transaction: Transaction) {
-    const options = {
-      where: {},
-      transaction: transaction
-    }
-
-    return ApplicationModel.update({ migrationVersion: newVersion }, options)
+  static load () {
+    return ApplicationModel.findOne()
   }
 }