aboutsummaryrefslogtreecommitdiffhomepage
path: root/server
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2021-08-26 10:00:12 +0200
committerChocobozzz <me@florianbigard.com>2021-08-26 10:01:42 +0200
commit7b6cf83e33c1cf9719f77338288b9145b8cdcf60 (patch)
tree6c3b213aca2cc298f4dbd70d1fb87bbe37154e15 /server
parent5a298a5a3d000f94c944d3711d4b0226a888df04 (diff)
downloadPeerTube-7b6cf83e33c1cf9719f77338288b9145b8cdcf60.tar.gz
PeerTube-7b6cf83e33c1cf9719f77338288b9145b8cdcf60.tar.zst
PeerTube-7b6cf83e33c1cf9719f77338288b9145b8cdcf60.zip
Fix redundancy remove on host redundancy update
Diffstat (limited to 'server')
-rw-r--r--server/controllers/api/server/redundancy.ts8
-rw-r--r--server/models/redundancy/video-redundancy.ts24
-rw-r--r--server/tests/api/redundancy/redundancy.ts31
3 files changed, 48 insertions, 15 deletions
diff --git a/server/controllers/api/server/redundancy.ts b/server/controllers/api/server/redundancy.ts
index 99d1c762b..e36c8d2db 100644
--- a/server/controllers/api/server/redundancy.ts
+++ b/server/controllers/api/server/redundancy.ts
@@ -106,9 +106,11 @@ async function updateRedundancy (req: express.Request, res: express.Response) {
106 106
107 await server.save() 107 await server.save()
108 108
109 // Async, could be long 109 if (server.redundancyAllowed !== true) {
110 removeRedundanciesOfServer(server.id) 110 // Async, could be long
111 .catch(err => logger.error('Cannot remove redundancy of %s.', server.host, { err })) 111 removeRedundanciesOfServer(server.id)
112 .catch(err => logger.error('Cannot remove redundancy of %s.', server.host, { err }))
113 }
112 114
113 return res.status(HttpStatusCode.NO_CONTENT_204).end() 115 return res.status(HttpStatusCode.NO_CONTENT_204).end()
114} 116}
diff --git a/server/models/redundancy/video-redundancy.ts b/server/models/redundancy/video-redundancy.ts
index d645be248..44c17f8e5 100644
--- a/server/models/redundancy/video-redundancy.ts
+++ b/server/models/redundancy/video-redundancy.ts
@@ -470,16 +470,34 @@ export class VideoRedundancyModel extends Model<Partial<AttributesOnly<VideoRedu
470 470
471 const query = { 471 const query = {
472 where: { 472 where: {
473 actorId: actor.id 473 [Op.and]: [
474 {
475 actorId: actor.id
476 },
477 {
478 [Op.or]: [
479 {
480 '$VideoStreamingPlaylist.id$': {
481 [Op.ne]: null
482 }
483 },
484 {
485 '$VideoFile.id$': {
486 [Op.ne]: null
487 }
488 }
489 ]
490 }
491 ]
474 }, 492 },
475 include: [ 493 include: [
476 { 494 {
477 model: VideoFileModel, 495 model: VideoFileModel.unscoped(),
478 required: false, 496 required: false,
479 include: [ buildVideoInclude() ] 497 include: [ buildVideoInclude() ]
480 }, 498 },
481 { 499 {
482 model: VideoStreamingPlaylistModel, 500 model: VideoStreamingPlaylistModel.unscoped(),
483 required: false, 501 required: false,
484 include: [ buildVideoInclude() ] 502 include: [ buildVideoInclude() ]
485 } 503 }
diff --git a/server/tests/api/redundancy/redundancy.ts b/server/tests/api/redundancy/redundancy.ts
index 3400b1d9a..fe42e5fa8 100644
--- a/server/tests/api/redundancy/redundancy.ts
+++ b/server/tests/api/redundancy/redundancy.ts
@@ -49,7 +49,7 @@ async function checkMagnetWebseeds (file: VideoFile, baseWebseeds: string[], ser
49 } 49 }
50} 50}
51 51
52async function createSingleServers (strategy: VideoRedundancyStrategy | null, additionalParams: any = {}, withWebtorrent = true) { 52async function createServers (strategy: VideoRedundancyStrategy | null, additionalParams: any = {}, withWebtorrent = true) {
53 const strategies: any[] = [] 53 const strategies: any[] = []
54 54
55 if (strategy !== null) { 55 if (strategy !== null) {
@@ -309,7 +309,7 @@ describe('Test videos redundancy', function () {
309 before(function () { 309 before(function () {
310 this.timeout(120000) 310 this.timeout(120000)
311 311
312 return createSingleServers(strategy) 312 return createServers(strategy)
313 }) 313 })
314 314
315 it('Should have 1 webseed on the first video', async function () { 315 it('Should have 1 webseed on the first video', async function () {
@@ -359,7 +359,7 @@ describe('Test videos redundancy', function () {
359 before(function () { 359 before(function () {
360 this.timeout(120000) 360 this.timeout(120000)
361 361
362 return createSingleServers(strategy) 362 return createServers(strategy)
363 }) 363 })
364 364
365 it('Should have 1 webseed on the first video', async function () { 365 it('Should have 1 webseed on the first video', async function () {
@@ -384,7 +384,20 @@ describe('Test videos redundancy', function () {
384 await checkStatsWith1Redundancy(strategy) 384 await checkStatsWith1Redundancy(strategy)
385 }) 385 })
386 386
387 it('Should unfollow on server 1 and remove duplicated videos', async function () { 387 it('Should unfollow server 3 and keep duplicated videos', async function () {
388 this.timeout(80000)
389
390 await servers[0].follows.unfollow({ target: servers[2] })
391
392 await waitJobs(servers)
393 await wait(5000)
394
395 await check2Webseeds()
396 await check1PlaylistRedundancies()
397 await checkStatsWith1Redundancy(strategy)
398 })
399
400 it('Should unfollow server 2 and remove duplicated videos', async function () {
388 this.timeout(80000) 401 this.timeout(80000)
389 402
390 await servers[0].follows.unfollow({ target: servers[1] }) 403 await servers[0].follows.unfollow({ target: servers[1] })
@@ -409,7 +422,7 @@ describe('Test videos redundancy', function () {
409 before(function () { 422 before(function () {
410 this.timeout(120000) 423 this.timeout(120000)
411 424
412 return createSingleServers(strategy, { min_views: 3 }) 425 return createServers(strategy, { min_views: 3 })
413 }) 426 })
414 427
415 it('Should have 1 webseed on the first video', async function () { 428 it('Should have 1 webseed on the first video', async function () {
@@ -480,7 +493,7 @@ describe('Test videos redundancy', function () {
480 before(async function () { 493 before(async function () {
481 this.timeout(120000) 494 this.timeout(120000)
482 495
483 await createSingleServers(strategy, { min_views: 3 }, false) 496 await createServers(strategy, { min_views: 3 }, false)
484 }) 497 })
485 498
486 it('Should have 0 playlist redundancy on the first video', async function () { 499 it('Should have 0 playlist redundancy on the first video', async function () {
@@ -542,7 +555,7 @@ describe('Test videos redundancy', function () {
542 before(function () { 555 before(function () {
543 this.timeout(120000) 556 this.timeout(120000)
544 557
545 return createSingleServers(null) 558 return createServers(null)
546 }) 559 })
547 560
548 it('Should have 1 webseed on the first video', async function () { 561 it('Should have 1 webseed on the first video', async function () {
@@ -621,7 +634,7 @@ describe('Test videos redundancy', function () {
621 before(async function () { 634 before(async function () {
622 this.timeout(120000) 635 this.timeout(120000)
623 636
624 await createSingleServers(strategy, { min_lifetime: '7 seconds', min_views: 0 }) 637 await createServers(strategy, { min_lifetime: '7 seconds', min_views: 0 })
625 638
626 await enableRedundancyOnServer1() 639 await enableRedundancyOnServer1()
627 }) 640 })
@@ -663,7 +676,7 @@ describe('Test videos redundancy', function () {
663 before(async function () { 676 before(async function () {
664 this.timeout(120000) 677 this.timeout(120000)
665 678
666 await createSingleServers(strategy, { min_lifetime: '7 seconds', min_views: 0 }) 679 await createServers(strategy, { min_lifetime: '7 seconds', min_views: 0 })
667 680
668 await enableRedundancyOnServer1() 681 await enableRedundancyOnServer1()
669 682