mirror of
https://github.com/ilri/dspace-statistics-api.git
synced 2025-07-01 04:01:54 +02:00
Move all imports to top of file
A few months ago I had an issue setting up mocking because I was trying to be clever importing these libraries only when I needed them rather than at the global scope. Someone pointed out to me that if the imports are at the top of the file Falcon will load them once when the WSGI server starts, whereas if they are in the on_get() or on_post() they will load for every request! Also, it seems that PEP8 recommends keeping imports at the top of the file anyways, so I will just do that. Imports sorted with isort. See: https://www.python.org/dev/peps/pep-0008/#imports
This commit is contained in:
@ -1,6 +1,7 @@
|
||||
import requests
|
||||
|
||||
from .config import SOLR_SERVER
|
||||
from .util import get_statistics_shards
|
||||
|
||||
|
||||
def get_views(solr_date_string: str, items: list):
|
||||
@ -11,7 +12,6 @@ def get_views(solr_date_string: str, items: list):
|
||||
:parameter items (list): a list of item IDs
|
||||
:returns: A dict of item IDs and views
|
||||
"""
|
||||
from .util import get_statistics_shards
|
||||
shards = get_statistics_shards()
|
||||
|
||||
# Join the UUIDs with "OR" and escape the hyphens for Solr
|
||||
@ -62,7 +62,6 @@ def get_downloads(solr_date_string: str, items: list):
|
||||
:parameter items (list): a list of item IDs
|
||||
:returns: A dict of item IDs and downloads
|
||||
"""
|
||||
from .util import get_statistics_shards
|
||||
shards = get_statistics_shards()
|
||||
|
||||
# Join the UUIDs with "OR" and escape the hyphens for Solr
|
||||
|
Reference in New Issue
Block a user