Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
D
dify
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
ai-tech
dify
Commits
e1045f01
Unverified
Commit
e1045f01
authored
Feb 12, 2024
by
takatost
Committed by
GitHub
Feb 12, 2024
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
pref: optimize add hit count query performance when dataset hit (#2436)
parent
e6d22fc3
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
8 additions
and
4 deletions
+8
-4
index_tool_callback_handler.py
api/core/callback_handler/index_tool_callback_handler.py
+8
-4
No files found.
api/core/callback_handler/index_tool_callback_handler.py
View file @
e1045f01
...
@@ -42,12 +42,16 @@ class DatasetIndexToolCallbackHandler:
...
@@ -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
)
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment