mirror of
https://git.mirrors.martin98.com/https://github.com/infiniflow/ragflow.git
synced 2025-04-17 19:50:01 +08:00
Fix: KB update_time changed whenever system relaunched (#6959)
### What problem does this PR solve? Fix KB update_time changed whenever system relaunched. #6953 ### Type of change - [x] Bug Fix (non-breaking change which fixes an issue)
This commit is contained in:
parent
9b789c2ae9
commit
98670c3755
@ -148,7 +148,7 @@ def init_llm_factory():
|
||||
pass
|
||||
break
|
||||
for kb_id in KnowledgebaseService.get_all_ids():
|
||||
KnowledgebaseService.update_by_id(kb_id, {"doc_num": DocumentService.get_kb_doc_count(kb_id)})
|
||||
KnowledgebaseService.update_document_number_in_init(kb_id=kb_id, doc_num=DocumentService.get_kb_doc_count(kb_id))
|
||||
|
||||
|
||||
|
||||
|
@ -394,3 +394,30 @@ class KnowledgebaseService(CommonService):
|
||||
data["doc_num"] = cls.model.doc_num + 1
|
||||
num = cls.model.update(data).where(cls.model.id == kb_id).execute()
|
||||
return num
|
||||
|
||||
@classmethod
|
||||
@DB.connection_context()
|
||||
def update_document_number_in_init(cls, kb_id, doc_num):
|
||||
"""
|
||||
Only use this function when init system
|
||||
"""
|
||||
ok, kb = cls.get_by_id(kb_id)
|
||||
if not ok:
|
||||
return
|
||||
kb.doc_num = doc_num
|
||||
|
||||
dirty_fields = kb.dirty_fields
|
||||
if cls.model._meta.combined.get("update_time") in dirty_fields:
|
||||
dirty_fields.remove(cls.model._meta.combined["update_time"])
|
||||
|
||||
if cls.model._meta.combined.get("update_date") in dirty_fields:
|
||||
dirty_fields.remove(cls.model._meta.combined["update_date"])
|
||||
|
||||
try:
|
||||
kb.save(only=dirty_fields)
|
||||
except ValueError as e:
|
||||
if str(e) == "no data to save!":
|
||||
pass # that's OK
|
||||
else:
|
||||
raise e
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user