From 823c34c07fc0df81110098ee1032e9d3ed70b662 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Thu, 11 May 2023 15:02:53 +0200 Subject: Fix reset sequelize instance --- server/controllers/api/video-channel.ts | 2 +- server/controllers/api/video-playlist.ts | 2 +- server/controllers/api/videos/update.ts | 2 +- server/helpers/database-utils.ts | 11 +---------- server/lib/activitypub/actors/updater.ts | 4 ++-- server/lib/activitypub/videos/updater.ts | 6 +++--- server/tests/api/live/live-fast-restream.ts | 7 +++---- server/tests/api/videos/single-server.ts | 2 +- 8 files changed, 13 insertions(+), 23 deletions(-) diff --git a/server/controllers/api/video-channel.ts b/server/controllers/api/video-channel.ts index 5b9fb794a..c6d144f79 100644 --- a/server/controllers/api/video-channel.ts +++ b/server/controllers/api/video-channel.ts @@ -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 } diff --git a/server/controllers/api/video-playlist.ts b/server/controllers/api/video-playlist.ts index 08b0f971d..de32dec88 100644 --- a/server/controllers/api/video-playlist.ts +++ b/server/controllers/api/video-playlist.ts @@ -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 } diff --git a/server/controllers/api/videos/update.ts b/server/controllers/api/videos/update.ts index e6197c4b1..5ab54a006 100644 --- a/server/controllers/api/videos/update.ts +++ b/server/controllers/api/videos/update.ts @@ -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 { diff --git a/server/helpers/database-utils.ts b/server/helpers/database-utils.ts index 0e6b35503..da8fb0d54 100644 --- a/server/helpers/database-utils.ts +++ b/server/helpers/database-utils.ts @@ -70,16 +70,8 @@ function transactionRetryer (func: (err: any, data: T) => any) { // --------------------------------------------------------------------------- -function updateInstanceWithAnother > (instanceToUpdate: T, baseInstance: U) { - const obj = baseInstance.toJSON() - - for (const key of Object.keys(obj)) { - instanceToUpdate[key] = obj[key] - } -} - function resetSequelizeInstance (instance: Model) { - instance.set(instance.previous()) + return instance.reload() } function filterNonExistingModels ( @@ -113,7 +105,6 @@ export { resetSequelizeInstance, retryTransactionWrapper, transactionRetryer, - updateInstanceWithAnother, afterCommitIfTransaction, filterNonExistingModels, deleteAllModels, diff --git a/server/lib/activitypub/actors/updater.ts b/server/lib/activitypub/actors/updater.ts index 73bdf1edc..5a92e7a22 100644 --- a/server/lib/activitypub/actors/updater.ts +++ b/server/lib/activitypub/actors/updater.ts @@ -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 diff --git a/server/lib/activitypub/videos/updater.ts b/server/lib/activitypub/videos/updater.ts index 3677dc3bb..6ddd2301b 100644 --- a/server/lib/activitypub/videos/updater.ts +++ b/server/lib/activitypub/videos/updater.ts @@ -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 diff --git a/server/tests/api/live/live-fast-restream.ts b/server/tests/api/live/live-fast-restream.ts index 4e30feaef..2169393c2 100644 --- a/server/tests/api/live/live-fast-restream.ts +++ b/server/tests/api/live/live-fast-restream.ts @@ -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) diff --git a/server/tests/api/videos/single-server.ts b/server/tests/api/videos/single-server.ts index 72f833ec2..9fd52933f 100644 --- a/server/tests/api/videos/single-server.ts +++ b/server/tests/api/videos/single-server.ts @@ -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', -- cgit v1.2.3