mirror of https://gitlab.com/brutaldon/brutaldon
Remove caching of Mastodon connections
There's not a good way of invalidating them, and they've started causing timeouts in this branch.
This commit is contained in:
parent
61c0edff75
commit
7b7c2d171d
|
@ -110,3 +110,4 @@ pip-selfcheck.json
|
||||||
/Pipfile.lock
|
/Pipfile.lock
|
||||||
/dev_https
|
/dev_https
|
||||||
node_modules
|
node_modules
|
||||||
|
/TAGS
|
||||||
|
|
|
@ -21,28 +21,20 @@ class Singleton(type):
|
||||||
cls._instances[cls] = super(Singleton, cls).__call__(*args, **kwargs)
|
cls._instances[cls] = super(Singleton, cls).__call__(*args, **kwargs)
|
||||||
return cls._instances[cls]
|
return cls._instances[cls]
|
||||||
|
|
||||||
class MastodonPool(dict, metaclass=Singleton):
|
|
||||||
pass
|
|
||||||
|
|
||||||
def get_usercontext(request):
|
def get_usercontext(request):
|
||||||
if is_logged_in(request):
|
if is_logged_in(request):
|
||||||
pool = MastodonPool()
|
|
||||||
try:
|
try:
|
||||||
client = Client.objects.get(api_base_id=request.session['instance'])
|
client = Client.objects.get(api_base_id=request.session['instance'])
|
||||||
user = Account.objects.get(username=request.session['username'])
|
user = Account.objects.get(username=request.session['username'])
|
||||||
except (Client.DoesNotExist, Client.MultipleObjectsReturned,
|
except (Client.DoesNotExist, Client.MultipleObjectsReturned,
|
||||||
Account.DoesNotExist, Account.MultipleObjectsReturned):
|
Account.DoesNotExist, Account.MultipleObjectsReturned):
|
||||||
raise NotLoggedInException()
|
raise NotLoggedInException()
|
||||||
if user.access_token in pool.keys():
|
mastodon = Mastodon(
|
||||||
mastodon = pool[user.access_token]
|
client_id = client.client_id,
|
||||||
else:
|
client_secret = client.client_secret,
|
||||||
mastodon = Mastodon(
|
access_token = user.access_token,
|
||||||
client_id = client.client_id,
|
api_base_url = client.api_base_id,
|
||||||
client_secret = client.client_secret,
|
ratelimit_method="throw")
|
||||||
access_token = user.access_token,
|
|
||||||
api_base_url = client.api_base_id,
|
|
||||||
ratelimit_method="throw")
|
|
||||||
pool[user.access_token] = mastodon
|
|
||||||
return user, mastodon
|
return user, mastodon
|
||||||
else:
|
else:
|
||||||
return None, None
|
return None, None
|
||||||
|
|
Loading…
Reference in New Issue