Skip to content

Commit 5257536

Browse files
committed
fix: 修复在对话日志中删除保存的文档,关联的问题未删除的缺陷
--bug=1049555 --user=王孝刚 【应用】将对话日志保存到文档后,在对话日志中删除保存的文档,关联的问题未删除 https://www.tapd.cn/57709429/s/1617726
1 parent aafc855 commit 5257536

File tree

3 files changed

+12
-5
lines changed

3 files changed

+12
-5
lines changed

apps/application/serializers/chat_message_serializers.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,7 @@ def handler(self,
154154
details=manage.get_details(),
155155
message_tokens=manage.context['message_tokens'],
156156
answer_tokens=manage.context['answer_tokens'],
157+
answer_text_list=[answer_text],
157158
run_time=manage.context['run_time'],
158159
index=len(chat_info.chat_record_list) + 1)
159160
chat_info.append_chat_record(chat_record, client_id)

apps/application/serializers/chat_serializers.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -608,13 +608,11 @@ def improve(self, instance: Dict, with_valid=True):
608608
title=instance.get("title") if 'title' in instance else '')
609609
problem_text = instance.get('problem_text') if instance.get(
610610
'problem_text') is not None else chat_record.problem_text
611-
problem = Problem(id=uuid.uuid1(), content=problem_text, dataset_id=dataset_id)
611+
problem, _ = Problem.objects.get_or_create(content=problem_text, dataset_id=dataset_id)
612612
problem_paragraph_mapping = ProblemParagraphMapping(id=uuid.uuid1(), dataset_id=dataset_id,
613613
document_id=document_id,
614614
problem_id=problem.id,
615615
paragraph_id=paragraph.id)
616-
# 插入问题
617-
problem.save()
618616
# 插入段落
619617
paragraph.save()
620618
# 插入关联问题

apps/dataset/serializers/paragraph_serializers.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -540,8 +540,16 @@ def delete(self, with_valid=False):
540540
if with_valid:
541541
self.is_valid(raise_exception=True)
542542
paragraph_id = self.data.get('paragraph_id')
543-
QuerySet(Paragraph).filter(id=paragraph_id).delete()
544-
QuerySet(ProblemParagraphMapping).filter(paragraph_id=paragraph_id).delete()
543+
Paragraph.objects.filter(id=paragraph_id).delete()
544+
545+
problem_id = ProblemParagraphMapping.objects.filter(paragraph_id=paragraph_id).values_list('problem_id',
546+
flat=True).first()
547+
548+
if problem_id is not None:
549+
if ProblemParagraphMapping.objects.filter(problem_id=problem_id).count() == 1:
550+
Problem.objects.filter(id=problem_id).delete()
551+
ProblemParagraphMapping.objects.filter(paragraph_id=paragraph_id).delete()
552+
545553
update_document_char_length(self.data.get('document_id'))
546554
delete_embedding_by_paragraph(paragraph_id)
547555

0 commit comments

Comments
 (0)