mirror of
https://github.com/open-webui/open-webui.git
synced 2026-08-28 05:27:35 +00:00
fix(knowledge): recover unlinked pending files and cap the pending poll
This commit is contained in:
parent
2856def6c0
commit
092351d76d
2 changed files with 41 additions and 26 deletions
|
|
@ -1495,24 +1495,39 @@ async def update_file_from_knowledge_by_id(
|
|||
detail=ERROR_MESSAGES.NOT_FOUND,
|
||||
)
|
||||
|
||||
# Validate the file actually belongs to this knowledge base
|
||||
if not await Knowledges.has_file(knowledge_id=id, file_id=form_data.file_id, db=db):
|
||||
raise HTTPException(
|
||||
status_code=status.HTTP_400_BAD_REQUEST,
|
||||
detail=ERROR_MESSAGES.NOT_FOUND,
|
||||
)
|
||||
is_linked = await Knowledges.has_file(knowledge_id=id, file_id=form_data.file_id, db=db)
|
||||
|
||||
# Remove content from the vector database
|
||||
await ASYNC_VECTOR_DB_CLIENT.delete(collection_name=knowledge.id, filter={'file_id': form_data.file_id})
|
||||
|
||||
# Add content to the vector database
|
||||
try:
|
||||
await process_file(
|
||||
request,
|
||||
ProcessFileForm(file_id=form_data.file_id, collection_name=id),
|
||||
user=user,
|
||||
db=db,
|
||||
)
|
||||
if is_linked:
|
||||
await ASYNC_VECTOR_DB_CLIENT.delete(
|
||||
collection_name=knowledge.id, filter={'file_id': form_data.file_id}
|
||||
)
|
||||
await process_file(
|
||||
request,
|
||||
ProcessFileForm(file_id=form_data.file_id, collection_name=id),
|
||||
user=user,
|
||||
db=db,
|
||||
)
|
||||
else:
|
||||
await process_file(
|
||||
request,
|
||||
ProcessFileForm(file_id=form_data.file_id),
|
||||
user=user,
|
||||
db=db,
|
||||
)
|
||||
await process_file(
|
||||
request,
|
||||
ProcessFileForm(file_id=form_data.file_id, collection_name=id),
|
||||
user=user,
|
||||
db=db,
|
||||
)
|
||||
await Knowledges.add_file_to_knowledge_by_id(
|
||||
knowledge_id=id,
|
||||
file_id=form_data.file_id,
|
||||
user_id=user.id,
|
||||
directory_id=form_data.directory_id,
|
||||
db=db,
|
||||
)
|
||||
except Exception as e:
|
||||
raise HTTPException(
|
||||
status_code=status.HTTP_400_BAD_REQUEST,
|
||||
|
|
@ -1585,14 +1600,8 @@ async def remove_file_from_knowledge_by_id(
|
|||
detail=ERROR_MESSAGES.NOT_FOUND,
|
||||
)
|
||||
|
||||
# Validate the file actually belongs to this knowledge base
|
||||
if not await Knowledges.has_file(knowledge_id=id, file_id=form_data.file_id, db=db):
|
||||
raise HTTPException(
|
||||
status_code=status.HTTP_400_BAD_REQUEST,
|
||||
detail=ERROR_MESSAGES.NOT_FOUND,
|
||||
)
|
||||
|
||||
await Knowledges.remove_file_from_knowledge_by_id(knowledge_id=id, file_id=form_data.file_id, db=db)
|
||||
if await Knowledges.has_file(knowledge_id=id, file_id=form_data.file_id, db=db):
|
||||
await Knowledges.remove_file_from_knowledge_by_id(knowledge_id=id, file_id=form_data.file_id, db=db)
|
||||
|
||||
# Remove content from the vector database
|
||||
try:
|
||||
|
|
|
|||
|
|
@ -139,6 +139,7 @@
|
|||
let deleteDirectoryContents = true;
|
||||
|
||||
let pendingPollTimer: ReturnType<typeof setInterval> | null = null;
|
||||
let pendingPollCount = 0;
|
||||
let externalTestQuery = '';
|
||||
let externalTestResult: {
|
||||
documents?: string[];
|
||||
|
|
@ -228,15 +229,20 @@
|
|||
|
||||
// Start polling for completion (if not already polling)
|
||||
if (!pendingPollTimer) {
|
||||
pendingPollCount = 0;
|
||||
pendingPollTimer = setInterval(async () => {
|
||||
pendingPollCount++;
|
||||
try {
|
||||
const still = await getPendingKnowledgeFiles(localStorage.token, knowledgeId);
|
||||
if (!still || still.length === 0) {
|
||||
if (!still || still.length === 0 || pendingPollCount >= 60) {
|
||||
clearInterval(pendingPollTimer);
|
||||
pendingPollTimer = null;
|
||||
init();
|
||||
}
|
||||
} catch {}
|
||||
} catch {
|
||||
clearInterval(pendingPollTimer);
|
||||
pendingPollTimer = null;
|
||||
}
|
||||
}, 5000);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue