Skip to content

Commit 3e9c3c0

Browse files
committed
feat: update UUID generation to use uuid7 for improved uniqueness across models
1 parent 1a60d8c commit 3e9c3c0

File tree

20 files changed

+45
-45
lines changed

20 files changed

+45
-45
lines changed

apps/application/chat_pipeline/step/chat_step/impl/base_chat_step.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
import logging
1010
import time
1111
import traceback
12-
import uuid
12+
import uuid_utils.compat as uuid
1313
from typing import List
1414

1515
from django.db.models import QuerySet
@@ -238,7 +238,7 @@ def execute_stream(self, message_list: List[BaseMessage],
238238
model_setting=None):
239239
chat_result, is_ai_chat = self.get_stream_result(message_list, chat_model, paragraph_list,
240240
no_references_setting, problem_text)
241-
chat_record_id = uuid.uuid1()
241+
chat_record_id = uuid.uuid7()
242242
r = StreamingHttpResponse(
243243
streaming_content=event_content(chat_result, chat_id, chat_record_id, paragraph_list,
244244
post_response_handler, manage, self, chat_model, message_list, problem_text,
@@ -286,7 +286,7 @@ def execute_block(self, message_list: List[BaseMessage],
286286
reasoning_content_end = model_setting.get('reasoning_content_end', '</think>')
287287
reasoning = Reasoning(reasoning_content_start,
288288
reasoning_content_end)
289-
chat_record_id = uuid.uuid1()
289+
chat_record_id = uuid.uuid7()
290290
# 调用模型
291291
try:
292292
chat_result, is_ai_chat = self.get_block_result(message_list, chat_model, paragraph_list,

apps/application/migrations/0001_initial.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ class Migration(migrations.Migration):
9090
fields=[
9191
('create_time', models.DateTimeField(auto_now_add=True, verbose_name='创建时间')),
9292
('update_time', models.DateTimeField(auto_now=True, verbose_name='修改时间')),
93-
('id', models.UUIDField(default=uuid.uuid1, editable=False, primary_key=True, serialize=False, verbose_name='主键id')),
93+
('id', models.UUIDField(default=uuid_utils.compat.uuid7, editable=False, primary_key=True, serialize=False, verbose_name='主键id')),
9494
('secret_key', models.CharField(max_length=1024, unique=True, verbose_name='秘钥')),
9595
('workspace_id', models.CharField(db_index=True, default='default', max_length=64, verbose_name='工作空间id')),
9696
('is_active', models.BooleanField(default=True, verbose_name='是否开启')),
@@ -162,7 +162,7 @@ class Migration(migrations.Migration):
162162
fields=[
163163
('create_time', models.DateTimeField(auto_now_add=True, verbose_name='创建时间')),
164164
('update_time', models.DateTimeField(auto_now=True, verbose_name='修改时间')),
165-
('id', models.UUIDField(default=uuid_utils.compat.uuid1, editable=False, primary_key=True, serialize=False, verbose_name='主键id')),
165+
('id', models.UUIDField(default=uuid_utils.compat.uuid7, editable=False, primary_key=True, serialize=False, verbose_name='主键id')),
166166
('vote_status', models.CharField(choices=[('-1', '未投票'), ('0', '赞同'), ('1', '反对')], default='-1', max_length=10, verbose_name='投票')),
167167
('problem_text', models.CharField(max_length=10240, verbose_name='问题')),
168168
('answer_text', models.CharField(max_length=40960, verbose_name='答案')),
@@ -185,7 +185,7 @@ class Migration(migrations.Migration):
185185
fields=[
186186
('create_time', models.DateTimeField(auto_now_add=True, verbose_name='创建时间')),
187187
('update_time', models.DateTimeField(auto_now=True, verbose_name='修改时间')),
188-
('id', models.UUIDField(default=uuid_utils.compat.uuid1, editable=False, primary_key=True, serialize=False, verbose_name='主键id')),
188+
('id', models.UUIDField(default=uuid_utils.compat.uuid7, editable=False, primary_key=True, serialize=False, verbose_name='主键id')),
189189
('workspace_id', models.CharField(db_index=True, default='default', max_length=64, verbose_name='工作空间id')),
190190
('name', models.CharField(default='', max_length=128, verbose_name='版本名称')),
191191
('publish_user_id', models.UUIDField(default=None, null=True, verbose_name='发布者id')),

apps/application/models/application.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ class Meta:
120120

121121

122122
class WorkFlowVersion(AppModelMixin):
123-
id = models.UUIDField(primary_key=True, max_length=128, default=uuid.uuid1, editable=False, verbose_name="主键id")
123+
id = models.UUIDField(primary_key=True, max_length=128, default=uuid.uuid7, editable=False, verbose_name="主键id")
124124
application = models.ForeignKey(Application, on_delete=models.CASCADE)
125125
workspace_id = models.CharField(max_length=64, verbose_name="工作空间id", default="default", db_index=True)
126126
name = models.CharField(verbose_name="版本名称", max_length=128, default="")

apps/application/models/application_api_key.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import uuid
1+
import uuid_utils.compat as uuid
22

33
from django.contrib.postgres.fields import ArrayField
44
from django.db import models
@@ -9,7 +9,7 @@
99

1010

1111
class ApplicationApiKey(AppModelMixin):
12-
id = models.UUIDField(primary_key=True, max_length=128, default=uuid.uuid1, editable=False, verbose_name="主键id")
12+
id = models.UUIDField(primary_key=True, max_length=128, default=uuid.uuid7, editable=False, verbose_name="主键id")
1313
secret_key = models.CharField(max_length=1024, verbose_name="秘钥", unique=True)
1414
user = models.ForeignKey(User, on_delete=models.CASCADE, verbose_name="用户id")
1515
workspace_id = models.CharField(max_length=64, verbose_name="工作空间id", default="default", db_index=True)

apps/application/models/application_chat.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ class ChatRecord(AppModelMixin):
4848
"""
4949
对话日志 详情
5050
"""
51-
id = models.UUIDField(primary_key=True, max_length=128, default=uuid.uuid1, editable=False, verbose_name="主键id")
51+
id = models.UUIDField(primary_key=True, max_length=128, default=uuid.uuid7, editable=False, verbose_name="主键id")
5252
chat = models.ForeignKey(Chat, on_delete=models.CASCADE)
5353
vote_status = models.CharField(verbose_name='投票', max_length=10, choices=VoteChoices.choices,
5454
default=VoteChoices.UN_VOTE)

apps/application/serializers/application.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -246,7 +246,7 @@ def is_valid(self, *, user_id=None, raise_exception=False):
246246

247247
@staticmethod
248248
def to_application_model(user_id: str, application: Dict):
249-
return Application(id=uuid.uuid1(), name=application.get('name'), desc=application.get('desc'),
249+
return Application(id=uuid.uuid7(), name=application.get('name'), desc=application.get('desc'),
250250
prologue=application.get('prologue'),
251251
dialogue_number=application.get('dialogue_number', 0),
252252
user_id=user_id, model_id=application.get('model_id'),
@@ -429,12 +429,12 @@ def insert_workflow(self, instance: Dict):
429429
application_model.save()
430430
# 插入认证信息
431431
ApplicationAccessToken(application_id=application_model.id,
432-
access_token=hashlib.md5(str(uuid.uuid1()).encode()).hexdigest()[8:24]).save()
432+
access_token=hashlib.md5(str(uuid.uuid7()).encode()).hexdigest()[8:24]).save()
433433
return ApplicationCreateSerializer.ApplicationResponse(application_model).data
434434

435435
@staticmethod
436436
def to_application_knowledge_mapping(application_id: str, dataset_id: str):
437-
return ApplicationKnowledgeMapping(id=uuid.uuid1(), application_id=application_id, dataset_id=dataset_id)
437+
return ApplicationKnowledgeMapping(id=uuid.uuid7(), application_id=application_id, dataset_id=dataset_id)
438438

439439
def insert_simple(self, instance: Dict):
440440
self.is_valid(raise_exception=True)
@@ -449,7 +449,7 @@ def insert_simple(self, instance: Dict):
449449
application_model.save()
450450
# 插入认证信息
451451
ApplicationAccessToken(application_id=application_model.id,
452-
access_token=hashlib.md5(str(uuid.uuid1()).encode()).hexdigest()[8:24]).save()
452+
access_token=hashlib.md5(str(uuid.uuid7()).encode()).hexdigest()[8:24]).save()
453453
# 插入关联数据
454454
QuerySet(ApplicationKnowledgeMapping).bulk_create(application_knowledge_mapping_model_list)
455455
return ApplicationCreateSerializer.ApplicationResponse(application_model).data
@@ -484,7 +484,7 @@ def import_(self, instance: dict, with_valid=True):
484484
application_model.save()
485485
# 插入认证信息
486486
ApplicationAccessToken(application_id=application_model.id,
487-
access_token=hashlib.md5(str(uuid.uuid1()).encode()).hexdigest()[8:24]).save()
487+
access_token=hashlib.md5(str(uuid.uuid7()).encode()).hexdigest()[8:24]).save()
488488
QuerySet(Tool).bulk_create(tool_model_list) if len(tool_model_list) > 0 else None
489489
return True
490490

@@ -511,7 +511,7 @@ def to_application(application, workspace_id, user_id):
511511
for node in work_flow.get('nodes', []):
512512
if node.get('type') == 'search-dataset-node':
513513
node.get('properties', {}).get('node_data', {})['dataset_id_list'] = []
514-
return Application(id=uuid.uuid1(),
514+
return Application(id=uuid.uuid7(),
515515
user_id=user_id,
516516
name=application.get('name'),
517517
workspace_id=workspace_id,

apps/application/serializers/application_access_token.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
@desc:
88
"""
99
import hashlib
10-
import uuid
10+
import uuid_utils.compat as uuid
1111

1212
from django.core.cache import cache
1313
from django.db.models import QuerySet
@@ -53,7 +53,7 @@ def edit(self, instance):
5353
if 'is_active' in instance:
5454
application_access_token.is_active = instance.get("is_active")
5555
if 'access_token_reset' in instance and instance.get('access_token_reset'):
56-
application_access_token.access_token = hashlib.md5(str(uuid.uuid1()).encode()).hexdigest()[8:24]
56+
application_access_token.access_token = hashlib.md5(str(uuid.uuid7()).encode()).hexdigest()[8:24]
5757
if 'access_num' in instance and instance.get('access_num') is not None:
5858
application_access_token.access_num = instance.get("access_num")
5959
if 'white_active' in instance and instance.get('white_active') is not None:
@@ -91,7 +91,7 @@ def one(self, with_valid=True):
9191
if application_access_token is None:
9292
application_access_token = ApplicationAccessToken(application_id=application_id,
9393
access_token=hashlib.md5(
94-
str(uuid.uuid1()).encode()).hexdigest()[
94+
str(uuid.uuid7()).encode()).hexdigest()[
9595
8:24], is_active=True)
9696
application_access_token.save()
9797
application_setting_model = DatabaseModelManage.get_model('application_setting')

apps/application/serializers/application_api_key.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,8 @@ def generate(self, with_valid=True):
4545
self.is_valid(raise_exception=True)
4646
application_id = self.data.get("application_id")
4747
application = QuerySet(Application).filter(id=application_id).first()
48-
secret_key = 'application-' + hashlib.md5(str(uuid.uuid1()).encode()).hexdigest()
49-
application_api_key = ApplicationApiKey(id=uuid.uuid1(),
48+
secret_key = 'application-' + hashlib.md5(str(uuid.uuid7()).encode()).hexdigest()
49+
application_api_key = ApplicationApiKey(id=uuid.uuid7(),
5050
secret_key=secret_key,
5151
user_id=application.user_id,
5252
application_id=application_id)

apps/application/serializers/application_chat_record.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
@date:2025/6/10 15:10
77
@desc:
88
"""
9-
import uuid
9+
import uuid_utils.compat as uuid
1010
from functools import reduce
1111
from typing import Dict
1212

@@ -208,15 +208,15 @@ def post_improve(self, instance: Dict):
208208
problem_paragraph_mappings = []
209209
for chat_record in chat_record_list:
210210
paragraph = Paragraph(
211-
id=uuid.uuid1(),
211+
id=uuid.uuid7(),
212212
document_id=document_id,
213213
content=chat_record.answer_text,
214214
knowledge_id=knowledge_id,
215215
title=chat_record.problem_text
216216
)
217217
problem, _ = Problem.objects.get_or_create(content=chat_record.problem_text, knowledge_id=knowledge_id)
218218
problem_paragraph_mapping = ProblemParagraphMapping(
219-
id=uuid.uuid1(),
219+
id=uuid.uuid7(),
220220
knowledge_id=knowledge_id,
221221
document_id=document_id,
222222
problem_id=problem.id,
@@ -284,7 +284,7 @@ def improve(self, instance: Dict, with_valid=True):
284284
max_position=Max('position')
285285
)['max_position'] or 0
286286
paragraph = Paragraph(
287-
id=uuid.uuid1(),
287+
id=uuid.uuid7(),
288288
document_id=document_id,
289289
content=instance.get("content"),
290290
knowledge_id=knowledge_id,
@@ -294,7 +294,7 @@ def improve(self, instance: Dict, with_valid=True):
294294
problem_text = instance.get('problem_text') if instance.get(
295295
'problem_text') is not None else chat_record.problem_text
296296
problem, _ = QuerySet(Problem).get_or_create(content=problem_text, knowledge_id=knowledge_id)
297-
problem_paragraph_mapping = ProblemParagraphMapping(id=uuid.uuid1(), knowledge_id=knowledge_id,
297+
problem_paragraph_mapping = ProblemParagraphMapping(id=uuid.uuid7(), knowledge_id=knowledge_id,
298298
document_id=document_id,
299299
problem_id=problem.id,
300300
paragraph_id=paragraph.id)

apps/application/views/application_chat.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
@date:2025/6/10 11:00
77
@desc:
88
"""
9-
import uuid
9+
import uuid_utils.compat as uuid
1010

1111
from django.utils.translation import gettext_lazy as _
1212
from drf_spectacular.utils import extend_schema
@@ -114,7 +114,7 @@ class OpenView(APIView):
114114
def get(self, request: Request, workspace_id: str, application_id: str):
115115
return result.success(OpenChatSerializers(
116116
data={'workspace_id': workspace_id, 'application_id': application_id,
117-
'chat_user_id': str(uuid.uuid1()), 'chat_user_type': ChatUserType.ANONYMOUS_USER,
117+
'chat_user_id': str(uuid.uuid7()), 'chat_user_type': ChatUserType.ANONYMOUS_USER,
118118
'debug': True}).open())
119119

120120

0 commit comments

Comments
 (0)