mirror of
https://github.com/khoaliber/khoj.git
synced 2026-03-09 13:25:11 +00:00
Merge pull request #268 from khoj-ai/fix/threading-issue-in-update-api
Add try-except-finally blocks around configure calls in /update
This commit is contained in:
@@ -93,6 +93,7 @@ def configure_search(model: SearchModels, config: FullConfig, regenerate: bool,
|
|||||||
logger.warning("🚨 No Content or Search type is configured.")
|
logger.warning("🚨 No Content or Search type is configured.")
|
||||||
return
|
return
|
||||||
|
|
||||||
|
try:
|
||||||
# Initialize Org Notes Search
|
# Initialize Org Notes Search
|
||||||
if (t == state.SearchType.Org or t == None) and config.content_type.org and config.search_type.asymmetric:
|
if (t == state.SearchType.Org or t == None) and config.content_type.org and config.search_type.asymmetric:
|
||||||
logger.info("🦄 Setting up search for orgmode notes")
|
logger.info("🦄 Setting up search for orgmode notes")
|
||||||
@@ -118,7 +119,11 @@ def configure_search(model: SearchModels, config: FullConfig, regenerate: bool,
|
|||||||
)
|
)
|
||||||
|
|
||||||
# Initialize Markdown Search
|
# Initialize Markdown Search
|
||||||
if (t == state.SearchType.Markdown or t == None) and config.content_type.markdown and config.search_type.asymmetric:
|
if (
|
||||||
|
(t == state.SearchType.Markdown or t == None)
|
||||||
|
and config.content_type.markdown
|
||||||
|
and config.search_type.asymmetric
|
||||||
|
):
|
||||||
logger.info("💎 Setting up search for markdown notes")
|
logger.info("💎 Setting up search for markdown notes")
|
||||||
# Extract Entries, Generate Markdown Embeddings
|
# Extract Entries, Generate Markdown Embeddings
|
||||||
model.markdown_search = text_search.setup(
|
model.markdown_search = text_search.setup(
|
||||||
@@ -184,6 +189,9 @@ def configure_search(model: SearchModels, config: FullConfig, regenerate: bool,
|
|||||||
regenerate=regenerate,
|
regenerate=regenerate,
|
||||||
filters=[DateFilter(), WordFilter(), FileFilter()],
|
filters=[DateFilter(), WordFilter(), FileFilter()],
|
||||||
)
|
)
|
||||||
|
except Exception as e:
|
||||||
|
logger.error("🚨 Failed to setup search")
|
||||||
|
raise e
|
||||||
|
|
||||||
# Invalidate Query Cache
|
# Invalidate Query Cache
|
||||||
state.query_cache = LRU()
|
state.query_cache = LRU()
|
||||||
|
|||||||
@@ -357,7 +357,12 @@ def update(
|
|||||||
):
|
):
|
||||||
try:
|
try:
|
||||||
state.search_index_lock.acquire()
|
state.search_index_lock.acquire()
|
||||||
|
try:
|
||||||
state.model = configure_search(state.model, state.config, regenerate=force or False, t=t)
|
state.model = configure_search(state.model, state.config, regenerate=force or False, t=t)
|
||||||
|
except Exception as e:
|
||||||
|
logger.error(e)
|
||||||
|
raise HTTPException(status_code=500, detail=str(e))
|
||||||
|
finally:
|
||||||
state.search_index_lock.release()
|
state.search_index_lock.release()
|
||||||
except ValueError as e:
|
except ValueError as e:
|
||||||
logger.error(e)
|
logger.error(e)
|
||||||
|
|||||||
Reference in New Issue
Block a user