Skip to content

Commit cd25bcf

Browse files
committed
refactor: adjust paragraph position handling to insert new paragraphs at the top
--bug=1057642 --user=刘瑞斌 【知识库】文档中添加分段,最后添加的没显示在最上面 https://www.tapd.cn/62980211/s/1719802
1 parent 276378a commit cd25bcf

File tree

1 file changed

+4
-7
lines changed

1 file changed

+4
-7
lines changed

apps/knowledge/serializers/paragraph.py

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -258,18 +258,15 @@ def save(self, instance: Dict, with_valid=True, with_embedding=True):
258258
problem_model_list, problem_paragraph_mapping_list = (
259259
ProblemParagraphManage(problem_paragraph_object_list, knowledge_id)
260260
.to_problem_model_list())
261-
# 插入段落
262-
max_position = Paragraph.objects.filter(document_id=document_id).aggregate(
263-
max_position=Max('position')
264-
)['max_position'] or 0
265-
paragraph.position = max_position + 1
261+
# 新加的在最上面
262+
paragraph.position = 0
266263
paragraph.save()
267264
# 调整位置
268265
if 'position' in instance:
269266
if type(instance['position']) is not int:
270-
instance['position'] = max_position + 1
267+
instance['position'] = 0
271268
else:
272-
instance['position'] = max_position + 1
269+
instance['position'] = 0
273270

274271
ParagraphSerializers.AdjustPosition(data={
275272
'paragraph_id': str(paragraph.id),

0 commit comments

Comments
 (0)