Improve KV storage initialize logic
This commit is contained in:
@@ -33,10 +33,10 @@ class JsonDocStatusStorage(DocStatusStorage):
|
|||||||
async def initialize(self):
|
async def initialize(self):
|
||||||
"""Initialize storage data"""
|
"""Initialize storage data"""
|
||||||
self._storage_lock = get_storage_lock()
|
self._storage_lock = get_storage_lock()
|
||||||
self._data = await get_namespace_data(self.namespace)
|
|
||||||
async with get_data_init_lock():
|
async with get_data_init_lock():
|
||||||
# check need_init must before get_namespace_data
|
# check need_init must before get_namespace_data
|
||||||
need_init = await try_initialize_namespace(self.namespace)
|
need_init = await try_initialize_namespace(self.namespace)
|
||||||
|
self._data = await get_namespace_data(self.namespace)
|
||||||
if need_init:
|
if need_init:
|
||||||
loaded_data = load_json(self._file_name) or {}
|
loaded_data = load_json(self._file_name) or {}
|
||||||
async with self._storage_lock:
|
async with self._storage_lock:
|
||||||
|
@@ -29,10 +29,10 @@ class JsonKVStorage(BaseKVStorage):
|
|||||||
async def initialize(self):
|
async def initialize(self):
|
||||||
"""Initialize storage data"""
|
"""Initialize storage data"""
|
||||||
self._storage_lock = get_storage_lock()
|
self._storage_lock = get_storage_lock()
|
||||||
self._data = await get_namespace_data(self.namespace)
|
|
||||||
async with get_data_init_lock():
|
async with get_data_init_lock():
|
||||||
# check need_init must before get_namespace_data
|
# check need_init must before get_namespace_data
|
||||||
need_init = await try_initialize_namespace(self.namespace)
|
need_init = await try_initialize_namespace(self.namespace)
|
||||||
|
self._data = await get_namespace_data(self.namespace)
|
||||||
if need_init:
|
if need_init:
|
||||||
loaded_data = load_json(self._file_name) or {}
|
loaded_data = load_json(self._file_name) or {}
|
||||||
async with self._storage_lock:
|
async with self._storage_lock:
|
||||||
|
Reference in New Issue
Block a user