]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/commitdiff
Fix reset sequelize instance
authorChocobozzz <me@florianbigard.com>
Thu, 11 May 2023 13:02:53 +0000 (15:02 +0200)
committerChocobozzz <me@florianbigard.com>
Thu, 11 May 2023 13:03:47 +0000 (15:03 +0200)
server/controllers/api/video-channel.ts
server/controllers/api/video-playlist.ts
server/controllers/api/videos/update.ts
server/helpers/database-utils.ts
server/lib/activitypub/actors/updater.ts
server/lib/activitypub/videos/updater.ts
server/tests/api/live/live-fast-restream.ts
server/tests/api/videos/single-server.ts

index 5b9fb794ae9bb94a7afba909efc060aa59e34a48..c6d144f79290a89ce4b474f110921d9cf6df00f0 100644 (file)
@@ -310,7 +310,7 @@ async function updateVideoChannel (req: express.Request, res: express.Response)
 
     // If the transaction is retried, sequelize will think the object has not changed
     // So we need to restore the previous fields
-    resetSequelizeInstance(videoChannelInstance)
+    await resetSequelizeInstance(videoChannelInstance)
 
     throw err
   }
index 08b0f971d516515a6f28bc8783db0aa5f7411b35..de32dec88d2a26015d8f11d2f1e0b0cc441cb303 100644 (file)
@@ -276,7 +276,7 @@ async function updateVideoPlaylist (req: express.Request, res: express.Response)
 
     // If the transaction is retried, sequelize will think the object has not changed
     // So we need to restore the previous fields
-    resetSequelizeInstance(videoPlaylistInstance)
+    await resetSequelizeInstance(videoPlaylistInstance)
 
     throw err
   }
index e6197c4b1b87dd973a3cb510cfc5f645decd95bd..5ab54a00678ba8b151b0e5f7310a6b5aa84a913e 100644 (file)
@@ -152,7 +152,7 @@ async function updateVideo (req: express.Request, res: express.Response) {
   } catch (err) {
     // If the transaction is retried, sequelize will think the object has not changed
     // So we need to restore the previous fields
-    resetSequelizeInstance(videoFromReq)
+    await resetSequelizeInstance(videoFromReq)
 
     throw err
   } finally {
index 0e6b3550371e721624652166ea03d2435538b5c6..da8fb0d54677acc04e3ff47b3c0d15d5dab956ec 100644 (file)
@@ -70,16 +70,8 @@ function transactionRetryer <T> (func: (err: any, data: T) => any) {
 
 // ---------------------------------------------------------------------------
 
-function updateInstanceWithAnother <M, T extends U, U extends Model<M>> (instanceToUpdate: T, baseInstance: U) {
-  const obj = baseInstance.toJSON()
-
-  for (const key of Object.keys(obj)) {
-    instanceToUpdate[key] = obj[key]
-  }
-}
-
 function resetSequelizeInstance <T> (instance: Model<T>) {
-  instance.set(instance.previous())
+  return instance.reload()
 }
 
 function filterNonExistingModels <T extends { hasSameUniqueKeysThan (other: T): boolean }> (
@@ -113,7 +105,6 @@ export {
   resetSequelizeInstance,
   retryTransactionWrapper,
   transactionRetryer,
-  updateInstanceWithAnother,
   afterCommitIfTransaction,
   filterNonExistingModels,
   deleteAllModels,
index 73bdf1edc9ea9ed4fa3e3ab44024aaab38295731..5a92e7a2241cc6c8fbfc129ce7f50e66f244d7be 100644 (file)
@@ -52,11 +52,11 @@ export class APActorUpdater {
       logger.info('Remote account %s updated', this.actorObject.url)
     } catch (err) {
       if (this.actor !== undefined) {
-        resetSequelizeInstance(this.actor)
+        await resetSequelizeInstance(this.actor)
       }
 
       if (this.accountOrChannel !== undefined) {
-        resetSequelizeInstance(this.accountOrChannel)
+        await resetSequelizeInstance(this.accountOrChannel)
       }
 
       // This is just a debug because we will retry the insert
index 3677dc3bb558abf90d47c024a0d00f68fa1d145c..6ddd2301b0e917421e7c8a978089704905e8b391 100644 (file)
@@ -88,7 +88,7 @@ export class APVideoUpdater extends APVideoAbstractBuilder {
 
       return videoUpdated
     } catch (err) {
-      this.catchUpdateError(err)
+      await this.catchUpdateError(err)
     }
   }
 
@@ -154,9 +154,9 @@ export class APVideoUpdater extends APVideoAbstractBuilder {
     videoUpdated.VideoLive = null
   }
 
-  private catchUpdateError (err: Error) {
+  private async catchUpdateError (err: Error) {
     if (this.video !== undefined) {
-      resetSequelizeInstance(this.video)
+      await resetSequelizeInstance(this.video)
     }
 
     // This is just a debug because we will retry the insert
index 4e30feaef23cf6db4546fbe81fdaf088d6162eb6..2169393c27fc0931caf8229d7726bd0af2e37083 100644 (file)
@@ -2,11 +2,10 @@
 
 import { expect } from 'chai'
 import { wait } from '@shared/core-utils'
-import { HttpStatusCode, LiveVideoCreate, VideoPrivacy } from '@shared/models'
+import { LiveVideoCreate, VideoPrivacy } from '@shared/models'
 import {
   cleanupTests,
   createSingleServer,
-  makeRawRequest,
   PeerTubeServer,
   setAccessTokensToServers,
   setDefaultVideoChannel,
@@ -81,8 +80,8 @@ describe('Fast restream in live', function () {
 
       try {
         await server.live.getSegmentFile({ videoUUID: liveId, segment: 0, playlistNumber: 0 })
-        await makeRawRequest({ url: video.streamingPlaylists[0].playlistUrl, expectedStatus: HttpStatusCode.OK_200 })
-        await makeRawRequest({ url: video.streamingPlaylists[0].segmentsSha256Url, expectedStatus: HttpStatusCode.OK_200 })
+        await server.streamingPlaylists.get({ url: video.streamingPlaylists[0].playlistUrl })
+        await server.streamingPlaylists.getSegmentSha256({ url: video.streamingPlaylists[0].segmentsSha256Url })
       } catch (err) {
         // FIXME: try to debug error in CI "Unexpected end of JSON input"
         console.error(err)
index 72f833ec2da9eb25f2b3d7810bd27bbea0b45c37..9fd52933f7cc9cfa7e2084d29a508fe4635967a4 100644 (file)
@@ -213,7 +213,7 @@ describe('Test a single server', function () {
     })
 
     it('Should upload 6 videos', async function () {
-      this.timeout(25000)
+      this.timeout(50000)
 
       const videos = new Set([
         'video_short.mp4', 'video_short.ogv', 'video_short.webm',