From 161b061d4e51eb1e2b2b7e9482d5299489ef7c45 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Fri, 28 Sep 2018 10:07:05 +0200 Subject: Remove duplicated videos on unfollow/delete redundancy --- server/controllers/api/server/follows.ts | 5 +++++ server/controllers/api/server/redundancy.ts | 6 ++++++ 2 files changed, 11 insertions(+) (limited to 'server/controllers') diff --git a/server/controllers/api/server/follows.ts b/server/controllers/api/server/follows.ts index a4eae6b45..d62400e42 100644 --- a/server/controllers/api/server/follows.ts +++ b/server/controllers/api/server/follows.ts @@ -17,6 +17,7 @@ import { import { followersSortValidator, followingSortValidator, followValidator } from '../../../middlewares/validators' import { ActorFollowModel } from '../../../models/activitypub/actor-follow' import { JobQueue } from '../../../lib/job-queue' +import { removeRedundancyOf } from '../../../lib/redundancy' const serverFollowsRouter = express.Router() serverFollowsRouter.get('/following', @@ -101,6 +102,10 @@ async function removeFollow (req: express.Request, res: express.Response, next: server.redundancyAllowed = false await server.save({ transaction: t }) + // Async, could be long + removeRedundancyOf(server.id) + .catch(err => logger.error('Cannot remove redundancy of %s.', server.host, err)) + await follow.destroy({ transaction: t }) }) diff --git a/server/controllers/api/server/redundancy.ts b/server/controllers/api/server/redundancy.ts index 4216b9e35..4140c4991 100644 --- a/server/controllers/api/server/redundancy.ts +++ b/server/controllers/api/server/redundancy.ts @@ -3,6 +3,8 @@ import { UserRight } from '../../../../shared/models/users' import { asyncMiddleware, authenticate, ensureUserHasRight } from '../../../middlewares' import { updateServerRedundancyValidator } from '../../../middlewares/validators/redundancy' import { ServerModel } from '../../../models/server/server' +import { removeRedundancyOf } from '../../../lib/redundancy' +import { logger } from '../../../helpers/logger' const serverRedundancyRouter = express.Router() @@ -28,5 +30,9 @@ async function updateRedundancy (req: express.Request, res: express.Response, ne await server.save() + // Async, could be long + removeRedundancyOf(server.id) + .catch(err => logger.error('Cannot remove redundancy of %s.', server.host, err)) + return res.sendStatus(204) } -- cgit v1.2.3