import { UserModel } from './user'
import { AvatarModel } from '../avatar/avatar'
import { VideoPlaylistModel } from '../video/video-playlist'
-import { CONSTRAINTS_FIELDS, WEBSERVER } from '../../initializers/constants'
+import { CONSTRAINTS_FIELDS, SERVER_ACTOR_NAME, WEBSERVER } from '../../initializers/constants'
import { FindOptions, IncludeOptions, Op, Transaction, WhereOptions } from 'sequelize'
import { AccountBlocklistModel } from './account-blocklist'
import { ServerBlocklistModel } from '../server/server-blocklist'
import { ActorFollowModel } from '../activitypub/actor-follow'
-import { MAccountActor, MAccountDefault, MAccountSummaryFormattable, MAccountFormattable } from '../../typings/models'
+import { MAccountActor, MAccountDefault, MAccountSummaryFormattable, MAccountFormattable, MAccountAP } from '../../typings/models'
import * as Bluebird from 'bluebird'
export enum ScopeNames {
@HasMany(() => VideoCommentModel, {
foreignKey: {
- allowNull: false
+ allowNull: true
},
onDelete: 'cascade',
hooks: true
})
BlockedAccounts: AccountBlocklistModel[]
+ private static cache: { [ id: string ]: any } = {}
+
@BeforeDestroy
static async sendDeleteIfOwned (instance: AccountModel, options) {
if (!instance.Actor) {
- instance.Actor = await instance.$get('Actor', { transaction: options.transaction }) as ActorModel
+ instance.Actor = await instance.$get('Actor', { transaction: options.transaction })
}
await ActorFollowModel.removeFollowsOf(instance.Actor.id, options.transaction)
}
static loadLocalByName (name: string): Bluebird<MAccountDefault> {
+ // The server actor never change, so we can easily cache it
+ if (name === SERVER_ACTOR_NAME && AccountModel.cache[name]) {
+ return Bluebird.resolve(AccountModel.cache[name])
+ }
+
const query = {
where: {
[ Op.or ]: [
}
return AccountModel.findOne(query)
+ .then(account => {
+ if (name === SERVER_ACTOR_NAME) {
+ AccountModel.cache[name] = account
+ }
+
+ return account
+ })
}
static loadByNameAndHost (name: string, host: string): Bluebird<MAccountDefault> {
}
}
- toActivityPubObject () {
- const obj = this.Actor.toActivityPubObject(this.name, 'Account')
+ toActivityPubObject (this: MAccountAP) {
+ const obj = this.Actor.toActivityPubObject(this.name)
return Object.assign(obj, {
summary: this.description