Try pooling API requests

This commit is contained in:
Jason McBrayer 2019-07-23 09:33:09 -04:00
parent 0efbc552b7
commit e1d758765d

View File

@ -26,17 +26,27 @@ from urllib import parse
from pdb import set_trace from pdb import set_trace
from inscriptis import get_text from inscriptis import get_text
from time import sleep from time import sleep
from requests import Session
import re import re
class NotLoggedInException(Exception): class NotLoggedInException(Exception):
pass pass
global sessons_cache
sessions_cache = {}
### ###
### Utility functions ### 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): def get_usercontext(request):
if is_logged_in(request): if is_logged_in(request):
@ -55,6 +65,7 @@ def get_usercontext(request):
client_secret=client.client_secret, client_secret=client.client_secret,
access_token=user.access_token, access_token=user.access_token,
api_base_url=client.api_base_id, api_base_url=client.api_base_id,
session = get_session(client.api_base_id),
ratelimit_method="throw", ratelimit_method="throw",
) )
return user, mastodon return user, mastodon