Cleanup follows of orphean actors

This commit is contained in:
Chocobozzz 2020-11-10 16:29:35 +01:00
parent b9cf3fb638
commit 2af337c839
No known key found for this signature in database
GPG Key ID: 583A612D890159BE
4 changed files with 42 additions and 11 deletions

View File

@ -23,7 +23,7 @@ import { CONFIG, registerConfigChangedHandler } from './config'
// --------------------------------------------------------------------------- // ---------------------------------------------------------------------------
const LAST_MIGRATION_VERSION = 545 const LAST_MIGRATION_VERSION = 550
// --------------------------------------------------------------------------- // ---------------------------------------------------------------------------

View File

@ -0,0 +1,27 @@
import * as Sequelize from 'sequelize'
async function up (utils: {
transaction: Sequelize.Transaction
queryInterface: Sequelize.QueryInterface
sequelize: Sequelize.Sequelize
}): Promise<void> {
const query = `
WITH t AS (
SELECT actor.id FROM actor
LEFT JOIN "videoChannel" ON "videoChannel"."actorId" = actor.id
LEFT JOIN account ON account."actorId" = "actor"."id"
WHERE "videoChannel".id IS NULL and "account".id IS NULL
) DELETE FROM "actorFollow" WHERE "actorId" IN (SELECT t.id FROM t) OR "targetActorId" in (SELECT t.id FROM t)
`
await utils.sequelize.query(query)
}
function down (options) {
throw new Error('Not implemented.')
}
export {
up,
down
}

View File

@ -228,6 +228,7 @@ export class AccountModel extends Model<AccountModel> {
} }
await ActorFollowModel.removeFollowsOf(instance.Actor.id, options.transaction) await ActorFollowModel.removeFollowsOf(instance.Actor.id, options.transaction)
if (instance.isOwned()) { if (instance.isOwned()) {
return sendDeleteActor(instance.Actor, options.transaction) return sendDeleteActor(instance.Actor, options.transaction)
} }

View File

@ -1,3 +1,5 @@
import * as Bluebird from 'bluebird'
import { FindOptions, literal, Op, ScopeOptions } from 'sequelize'
import { import {
AllowNull, AllowNull,
BeforeDestroy, BeforeDestroy,
@ -23,17 +25,8 @@ import {
isVideoChannelNameValid, isVideoChannelNameValid,
isVideoChannelSupportValid isVideoChannelSupportValid
} from '../../helpers/custom-validators/video-channels' } from '../../helpers/custom-validators/video-channels'
import { sendDeleteActor } from '../../lib/activitypub/send'
import { AccountModel, ScopeNames as AccountModelScopeNames, SummaryOptions as AccountSummaryOptions } from '../account/account'
import { ActorModel, unusedActorAttributesForAPI } from '../activitypub/actor'
import { buildServerIdsFollowedBy, buildTrigramSearchIndex, createSimilarityAttribute, getSort, throwIfNotValid } from '../utils'
import { VideoModel } from './video'
import { CONSTRAINTS_FIELDS, WEBSERVER } from '../../initializers/constants' import { CONSTRAINTS_FIELDS, WEBSERVER } from '../../initializers/constants'
import { ServerModel } from '../server/server' import { sendDeleteActor } from '../../lib/activitypub/send'
import { FindOptions, Op, literal, ScopeOptions } from 'sequelize'
import { AvatarModel } from '../avatar/avatar'
import { VideoPlaylistModel } from './video-playlist'
import * as Bluebird from 'bluebird'
import { import {
MChannelAccountDefault, MChannelAccountDefault,
MChannelActor, MChannelActor,
@ -42,6 +35,14 @@ import {
MChannelFormattable, MChannelFormattable,
MChannelSummaryFormattable MChannelSummaryFormattable
} from '../../types/models/video' } from '../../types/models/video'
import { AccountModel, ScopeNames as AccountModelScopeNames, SummaryOptions as AccountSummaryOptions } from '../account/account'
import { ActorModel, unusedActorAttributesForAPI } from '../activitypub/actor'
import { ActorFollowModel } from '../activitypub/actor-follow'
import { AvatarModel } from '../avatar/avatar'
import { ServerModel } from '../server/server'
import { buildServerIdsFollowedBy, buildTrigramSearchIndex, createSimilarityAttribute, getSort, throwIfNotValid } from '../utils'
import { VideoModel } from './video'
import { VideoPlaylistModel } from './video-playlist'
export enum ScopeNames { export enum ScopeNames {
FOR_API = 'FOR_API', FOR_API = 'FOR_API',
@ -293,6 +294,8 @@ export class VideoChannelModel extends Model<VideoChannelModel> {
instance.Actor = await instance.$get('Actor', { transaction: options.transaction }) instance.Actor = await instance.$get('Actor', { transaction: options.transaction })
} }
await ActorFollowModel.removeFollowsOf(instance.Actor.id, options.transaction)
if (instance.Actor.isOwned()) { if (instance.Actor.isOwned()) {
return sendDeleteActor(instance.Actor, options.transaction) return sendDeleteActor(instance.Actor, options.transaction)
} }