mirror of
https://git.mirrors.martin98.com/https://github.com/langgenius/dify.git
synced 2025-08-12 10:48:59 +08:00
pref: optimize add hit count query performance when dataset hit (#2436)
This commit is contained in:
parent
e6d22fc3a0
commit
e1045f01c6
@ -42,12 +42,16 @@ class DatasetIndexToolCallbackHandler:
|
|||||||
def on_tool_end(self, documents: list[Document]) -> None:
|
def on_tool_end(self, documents: list[Document]) -> None:
|
||||||
"""Handle tool end."""
|
"""Handle tool end."""
|
||||||
for document in documents:
|
for document in documents:
|
||||||
doc_id = document.metadata['doc_id']
|
query = db.session.query(DocumentSegment).filter(
|
||||||
|
DocumentSegment.index_node_id == document.metadata['doc_id']
|
||||||
|
)
|
||||||
|
|
||||||
|
# if 'dataset_id' in document.metadata:
|
||||||
|
if 'dataset_id' in document.metadata:
|
||||||
|
query = query.filter(DocumentSegment.dataset_id == document.metadata['dataset_id'])
|
||||||
|
|
||||||
# add hit count to document segment
|
# add hit count to document segment
|
||||||
db.session.query(DocumentSegment).filter(
|
query.update(
|
||||||
DocumentSegment.index_node_id == doc_id
|
|
||||||
).update(
|
|
||||||
{DocumentSegment.hit_count: DocumentSegment.hit_count + 1},
|
{DocumentSegment.hit_count: DocumentSegment.hit_count + 1},
|
||||||
synchronize_session=False
|
synchronize_session=False
|
||||||
)
|
)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user