-
Notifications
You must be signed in to change notification settings - Fork 2.4k
feat: 对话日志默认使用最后对话时间 #1616
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: 对话日志默认使用最后对话时间 #1616
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
from django.db import migrations, connection | ||
|
||
batch_update_update_time = """ | ||
UPDATE application_chat ac | ||
SET update_time = acr_max.max_update_time | ||
FROM ( | ||
SELECT chat_id, MAX(update_time) AS max_update_time | ||
FROM application_chat_record | ||
GROUP BY chat_id | ||
) acr_max | ||
WHERE ac.id = acr_max.chat_id; | ||
""" | ||
|
||
|
||
class Migration(migrations.Migration): | ||
dependencies = [ | ||
('application', '0019_application_file_upload_enable_and_more.py'), | ||
] | ||
|
||
operations = [ | ||
migrations.RunPython(batch_update_update_time), | ||
] | ||
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,6 +6,7 @@ | |
@date:2023/11/14 13:51 | ||
@desc: | ||
""" | ||
from datetime import datetime | ||
import uuid | ||
from typing import List, Dict | ||
from uuid import UUID | ||
|
@@ -125,7 +126,9 @@ def append_chat_record(self, chat_record: ChatRecord, client_id=None): | |
# 插入数据库 | ||
if not QuerySet(Chat).filter(id=self.chat_id).exists(): | ||
Chat(id=self.chat_id, application_id=self.application.id, abstract=chat_record.problem_text[0:1024], | ||
client_id=client_id).save() | ||
client_id=client_id, update_time=datetime.now()).save() | ||
else: | ||
Chat.objects.filter(id=self.chat_id).update(update_time=datetime.now()) | ||
# 插入会话记录 | ||
chat_record.save() | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 在上面给出的代码片段中,我发现了以下问题和改进建议: 问题:
Please provide more details about the specific issues you're referring to, but I think it might be beneficial for your project to refactor For example:
By doing so,
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -127,12 +127,12 @@ def get_query_set(self, select_ids=None): | |
"star_num": models.IntegerField(), | ||
'trample_num': models.IntegerField(), | ||
'comparer': models.CharField(), | ||
'application_chat.create_time': models.DateTimeField(), | ||
'application_chat.update_time': models.DateTimeField(), | ||
'application_chat.id': models.UUIDField(), })) | ||
|
||
base_query_dict = {'application_chat.application_id': self.data.get("application_id"), | ||
'application_chat.create_time__gte': start_time, | ||
'application_chat.create_time__lte': end_time, | ||
'application_chat.update_time__gte': start_time, | ||
'application_chat.update_time__lte': end_time, | ||
} | ||
if 'abstract' in self.data and self.data.get('abstract') is not None: | ||
base_query_dict['application_chat.abstract__icontains'] = self.data.get('abstract') | ||
|
@@ -158,7 +158,7 @@ def get_query_set(self, select_ids=None): | |
condition = base_condition & min_trample_query | ||
else: | ||
condition = base_condition | ||
return query_set.filter(condition).order_by("-application_chat.create_time") | ||
return query_set.filter(condition).order_by("-application_chat.update_time") | ||
|
||
def list(self, with_valid=True): | ||
if with_valid: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 这段代码主要涉及Python中的模型查询和SQL语句构建,以下是详细的分析: def __init__(self, *args, **kwargs): # 这一行的`*args, **kwargs`不是必需的部分,在这里我假设这是正确的写法。 这行似乎没有提供足够的上下文来确定是否有必要。但如果没有更多的信息,我们可以理解为这是一个类定义。如果要解决这个问题,请提供更多关于如何使用这个库或进行哪种类型的更改的信息。 在后续代码块中,存在一些可能存在问题或可以改进的地方:
请注意这里的讨论基于未提供的详细代码段,因此这些只是一种根据常见错误类型给出的基本建议。如果有具体的情况和要求,最好参照实际项目文档或开发者指南进一步指导解决问题。同时,建议在开发过程中不断审查和调整现有代码以寻找任何潜在的小缺陷或者是不必要的性能开销等。 |
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
以上代码未找到不合规之处,逻辑上没有发现明显错误或缺陷。然而,在2024年11月之前可能存在版本兼容性问题,可能会在更早的数据库中引入额外的数据,并且更新时间字段可能需要进一步完善和测试以确保其准确性和通用性。
如果有任何特定需求,请提供更多详细信息,以便我能进行更深入的分析并提供有效的反馈建议。