Cache for person actor json

master
Bob Mottram 2019-06-30 11:21:07 +01:00
parent 3b816df03a
commit 32d8119c9b
1 changed files with 12 additions and 1 deletions

View File

@ -21,6 +21,11 @@ try:
except ImportError:
from bs4 import BeautifulSoup
# cache of actor json
# If there are repeated lookups then this helps prevent a lot
# of needless network traffic
personCache = {}
def permitted(url: str,federationList) -> bool:
"""Is a url from one of the permitted domains?
"""
@ -64,6 +69,9 @@ def getPersonBox(session,wfRequest,boxName='inbox'):
personUrl = getUserUrl(wfRequest)
if not personUrl:
return None
if personCache.get(personUrl):
personJson=personCache[personUrl]
else:
personJson = getJson(session,personUrl,asHeader,None)
if not personJson.get(boxName):
return personPosts
@ -74,6 +82,9 @@ def getPersonBox(session,wfRequest,boxName='inbox'):
if personJson.get('publicKey'):
if personJson['publicKey'].get('publicKeyPem'):
pubKey=personJson['publicKey']['publicKeyPem']
personCache[personUrl]=personJson
return personJson[boxName],pubKey,personId
def getUserPosts(session,wfRequest,maxPosts,maxMentions,maxEmoji,maxAttachments,federationList) -> {}: