Performance improvement - Only reset backends loaded into memory (#4274)
This commit is contained in:
parent
a147eeac67
commit
3498689d9d
@ -2,6 +2,7 @@ from __future__ import unicode_literals
|
|||||||
|
|
||||||
import importlib
|
import importlib
|
||||||
import moto
|
import moto
|
||||||
|
import sys
|
||||||
|
|
||||||
|
|
||||||
decorators = [
|
decorators = [
|
||||||
@ -26,8 +27,16 @@ def backends():
|
|||||||
yield _import_backend(module_name, backends_name)
|
yield _import_backend(module_name, backends_name)
|
||||||
|
|
||||||
|
|
||||||
def named_backends():
|
def loaded_backends():
|
||||||
for name, (module_name, backends_name) in BACKENDS.items():
|
loaded_modules = sys.modules.keys()
|
||||||
|
loaded_modules = [m for m in loaded_modules if m.startswith("moto.")]
|
||||||
|
imported_backends = [
|
||||||
|
name
|
||||||
|
for name, (module_name, _) in BACKENDS.items()
|
||||||
|
if f"moto.{module_name}" in loaded_modules
|
||||||
|
]
|
||||||
|
for name in imported_backends:
|
||||||
|
module_name, backends_name = BACKENDS[name]
|
||||||
yield name, _import_backend(module_name, backends_name)
|
yield name, _import_backend(module_name, backends_name)
|
||||||
|
|
||||||
|
|
||||||
|
@ -840,7 +840,7 @@ class MotoAPIBackend(BaseBackend):
|
|||||||
def reset(self):
|
def reset(self):
|
||||||
import moto.backends as backends
|
import moto.backends as backends
|
||||||
|
|
||||||
for name, backends_ in backends.named_backends():
|
for name, backends_ in backends.loaded_backends():
|
||||||
if name == "moto_api":
|
if name == "moto_api":
|
||||||
continue
|
continue
|
||||||
for region_name, backend in backends_.items():
|
for region_name, backend in backends_.items():
|
||||||
|
@ -74,13 +74,13 @@ class MediaPackageBackend(BaseBackend):
|
|||||||
def __init__(self, region_name=None):
|
def __init__(self, region_name=None):
|
||||||
super(MediaPackageBackend, self).__init__()
|
super(MediaPackageBackend, self).__init__()
|
||||||
self.region_name = region_name
|
self.region_name = region_name
|
||||||
|
self._channels = OrderedDict()
|
||||||
|
self._origin_endpoints = OrderedDict()
|
||||||
|
|
||||||
def reset(self):
|
def reset(self):
|
||||||
region_name = self.region_name
|
region_name = self.region_name
|
||||||
self.__dict__ = {}
|
self.__dict__ = {}
|
||||||
self.__init__(region_name)
|
self.__init__(region_name)
|
||||||
self._channels = OrderedDict()
|
|
||||||
self._origin_endpoints = OrderedDict()
|
|
||||||
|
|
||||||
def create_channel(self, description, id, tags):
|
def create_channel(self, description, id, tags):
|
||||||
arn = "arn:aws:mediapackage:channel:{}".format(id)
|
arn = "arn:aws:mediapackage:channel:{}".format(id)
|
||||||
|
@ -68,10 +68,13 @@ class DomainDispatcherApplication(object):
|
|||||||
if pattern.match("http://%s" % host):
|
if pattern.match("http://%s" % host):
|
||||||
return backend
|
return backend
|
||||||
|
|
||||||
print(
|
if "amazonaws.com" in host:
|
||||||
"Unable to find appropriate URL for {}."
|
print(
|
||||||
"Remember to add the URL to urls.py, and run script/update_backend_index.py to index it."
|
"Unable to find appropriate backend for {}."
|
||||||
)
|
"Remember to add the URL to urls.py, and run script/update_backend_index.py to index it.".format(
|
||||||
|
host
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
def infer_service_region_host(self, environ):
|
def infer_service_region_host(self, environ):
|
||||||
auth = environ.get("HTTP_AUTHORIZATION")
|
auth = environ.get("HTTP_AUTHORIZATION")
|
||||||
|
Loading…
Reference in New Issue
Block a user