Merge pull request #5354 from FinnStutzenstein/fixUnnenessaryBrokenLock

Fix unnecessary and unfunctional lock for production usage with gunicorn
This commit is contained in:
Emanuel Schütze 2020-05-06 17:29:28 +02:00 committed by GitHub
commit 5aa895bda2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -1,4 +1,3 @@
import asyncio
from typing import Any, Callable, Dict, Iterable, Optional, TypeVar, Union, cast from typing import Any, Callable, Dict, Iterable, Optional, TypeVar, Union, cast
from asgiref.sync import async_to_sync from asgiref.sync import async_to_sync
@ -28,8 +27,6 @@ INPUT_TYPE_MAPPING = {
ALLOWED_NONE = ("datetimepicker",) ALLOWED_NONE = ("datetimepicker",)
build_key_to_id_lock = asyncio.Lock()
class ConfigHandler: class ConfigHandler:
""" """
@ -77,25 +74,18 @@ class ConfigHandler:
async def build_key_to_id(self) -> None: async def build_key_to_id(self) -> None:
""" """
Build the key_to_id dict. Build the key_to_id dict, if it does not exists.
Recreates it, if it does not exists.
This uses the element_cache. It expects, that the config values are in the database
before this is called.
""" """
async with build_key_to_id_lock: if self.key_to_id is not None:
# Another worker could have build the key_to_id_dict, check and return early return
if self.key_to_id is not None:
return
config_full_data = await element_cache.get_collection_data( config_full_data = await element_cache.get_collection_data(
self.get_collection_string() self.get_collection_string()
) )
elements = config_full_data.values() elements = config_full_data.values()
self.key_to_id = {} self.key_to_id = {}
for element in elements: for element in elements:
self.key_to_id[element["key"]] = element["id"] self.key_to_id[element["key"]] = element["id"]
def exists(self, key: str) -> bool: def exists(self, key: str) -> bool:
""" """