From e1d758765dc41858cff7bef4f7d5a87e4f8ba9f0 Mon Sep 17 00:00:00 2001 From: Jason McBrayer Date: Tue, 23 Jul 2019 09:33:09 -0400 Subject: [PATCH] Try pooling API requests --- brutaldon/views.py | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/brutaldon/views.py b/brutaldon/views.py index e98c296..69e3d1f 100644 --- a/brutaldon/views.py +++ b/brutaldon/views.py @@ -26,17 +26,27 @@ from urllib import parse from pdb import set_trace from inscriptis import get_text from time import sleep +from requests import Session import re class NotLoggedInException(Exception): pass +global sessons_cache +sessions_cache = {} ### ### Utility functions ### +def get_session(domain): + if domain in sessions_cache: + return sessions_cache[domain] + else: + s = Session() + sessions_cache[domain] = s + return s def get_usercontext(request): if is_logged_in(request): @@ -55,6 +65,7 @@ def get_usercontext(request): client_secret=client.client_secret, access_token=user.access_token, api_base_url=client.api_base_id, + session = get_session(client.api_base_id), ratelimit_method="throw", ) return user, mastodon