aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/models/activitypub
diff options
context:
space:
mode:
Diffstat (limited to 'server/models/activitypub')
-rw-r--r--server/models/activitypub/actor.ts37
1 files changed, 32 insertions, 5 deletions
diff --git a/server/models/activitypub/actor.ts b/server/models/activitypub/actor.ts
index 007647ced..d651a281a 100644
--- a/server/models/activitypub/actor.ts
+++ b/server/models/activitypub/actor.ts
@@ -43,7 +43,7 @@ import {
43 MActorFull, 43 MActorFull,
44 MActorHost, 44 MActorHost,
45 MActorServer, 45 MActorServer,
46 MActorSummaryFormattable, 46 MActorSummaryFormattable, MActorUrl,
47 MActorWithInboxes 47 MActorWithInboxes
48} from '../../typings/models' 48} from '../../typings/models'
49import * as Bluebird from 'bluebird' 49import * as Bluebird from 'bluebird'
@@ -276,7 +276,8 @@ export class ActorModel extends Model<ActorModel> {
276 }) 276 })
277 VideoChannel: VideoChannelModel 277 VideoChannel: VideoChannelModel
278 278
279 private static cache: { [ id: string ]: any } = {} 279 private static localNameCache: { [ id: string ]: any } = {}
280 private static localUrlCache: { [ id: string ]: any } = {}
280 281
281 static load (id: number): Bluebird<MActor> { 282 static load (id: number): Bluebird<MActor> {
282 return ActorModel.unscoped().findByPk(id) 283 return ActorModel.unscoped().findByPk(id)
@@ -345,8 +346,8 @@ export class ActorModel extends Model<ActorModel> {
345 346
346 static loadLocalByName (preferredUsername: string, transaction?: Transaction): Bluebird<MActorFull> { 347 static loadLocalByName (preferredUsername: string, transaction?: Transaction): Bluebird<MActorFull> {
347 // The server actor never change, so we can easily cache it 348 // The server actor never change, so we can easily cache it
348 if (preferredUsername === SERVER_ACTOR_NAME && ActorModel.cache[preferredUsername]) { 349 if (preferredUsername === SERVER_ACTOR_NAME && ActorModel.localNameCache[preferredUsername]) {
349 return Bluebird.resolve(ActorModel.cache[preferredUsername]) 350 return Bluebird.resolve(ActorModel.localNameCache[preferredUsername])
350 } 351 }
351 352
352 const query = { 353 const query = {
@@ -361,7 +362,33 @@ export class ActorModel extends Model<ActorModel> {
361 .findOne(query) 362 .findOne(query)
362 .then(actor => { 363 .then(actor => {
363 if (preferredUsername === SERVER_ACTOR_NAME) { 364 if (preferredUsername === SERVER_ACTOR_NAME) {
364 ActorModel.cache[ preferredUsername ] = actor 365 ActorModel.localNameCache[ preferredUsername ] = actor
366 }
367
368 return actor
369 })
370 }
371
372 static loadLocalUrlByName (preferredUsername: string, transaction?: Transaction): Bluebird<MActorUrl> {
373 // The server actor never change, so we can easily cache it
374 if (preferredUsername === SERVER_ACTOR_NAME && ActorModel.localUrlCache[preferredUsername]) {
375 return Bluebird.resolve(ActorModel.localUrlCache[preferredUsername])
376 }
377
378 const query = {
379 attributes: [ 'url' ],
380 where: {
381 preferredUsername,
382 serverId: null
383 },
384 transaction
385 }
386
387 return ActorModel.unscoped()
388 .findOne(query)
389 .then(actor => {
390 if (preferredUsername === SERVER_ACTOR_NAME) {
391 ActorModel.localUrlCache[ preferredUsername ] = actor
365 } 392 }
366 393
367 return actor 394 return actor