Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion apps/dataset/serializers/document_serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -653,7 +653,13 @@ def cancel(self, instance, with_valid=True):
document_id=document_id).values('id'),
TaskType(instance.get('type')),
State.REVOKE)
ListenerManagement.update_status(QuerySet(Document).filter(id=document_id), TaskType(instance.get('type')),
ListenerManagement.update_status(QuerySet(Document).annotate(
reversed_status=Reverse('status'),
task_type_status=Substr('reversed_status', TaskType(instance.get('type')).value,
TaskType(instance.get('type')).value),
).filter(task_type_status__in=[State.PENDING.value, State.STARTED.value]).filter(
id=document_id).values('id'),
TaskType(instance.get('type')),
State.REVOKE)

return True
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

该段代码存在一些问题和可以改进的地方。

首先,在update_status()方法中,如果只更新了记录的状态,那么可能会丢失其他字段的信息。为了解决这个问题,需要确保在查询结果后执行额外的操作以获取所有列的数据。

此外,由于使用了字符串运算(__str__())以及字典索引进行赋值操作,可能存在性能不佳的情况。因此,应当使用Python内置的方式替换这些方式以便于提高程序的运行效率。

最后,应该避免直接对数据库中的数据进行修改(例如通过改变其状态或取消当前的任务),而应利用事务来进行控制以保证安全性。这样能够有效地解决并发访问时可能出现的问题,并且提高了整体的健壮性和稳定性。

Expand Down
Loading