Skip to content
Merged
Show file tree
Hide file tree
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
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ def migrate_historical_tokens(apps, schema_editor):
ChatUserTokenQuota = apps.get_model('system_manage', 'ChatUserTokenQuota')

chat_user_map = {
str(c['id']): c['chat_user_id']
str(c['id']): str(c['chat_user_id'])
for c in Chat.objects.values('id', 'chat_user_id').iterator()
}
user_totals = {}
Expand All @@ -24,10 +24,11 @@ def migrate_historical_tokens(apps, schema_editor):
user_totals[user_id] = user_totals.get(user_id, 0) + tokens

objs = [
ChatUserTokenQuota(user_id=uid, total_tokens=total)
ChatUserTokenQuota(user_id=uid, total_tokens=total, used_tokens=total)
for uid, total in user_totals.items()
]
ChatUserTokenQuota.objects.bulk_create(objs, batch_size=500)
if objs:
ChatUserTokenQuota.objects.bulk_create(objs, batch_size=500)


class Migration(migrations.Migration):
Expand All @@ -51,7 +52,7 @@ class Migration(migrations.Migration):
verbose_name="主键id",
),
),
("user_id", models.UUIDField(unique=True, verbose_name="用户id")),
("user_id", models.CharField(db_index=True, max_length=128, unique=True, verbose_name="用户id")),
(
"quota_type",
models.CharField(
Expand Down
2 changes: 1 addition & 1 deletion apps/system_manage/models/chat_user_token_quota.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ class ChatUserTokenQuota(AppModelMixin):
"""
id = models.UUIDField(primary_key=True, max_length=128, default=uuid.uuid7, editable=False, verbose_name="主键id")

user_id = models.UUIDField(max_length=128, unique=True, verbose_name="用户id")
user_id = models.CharField(max_length=128, unique=True, verbose_name="用户id", db_index=True)

quota_type = models.CharField(max_length=20, choices=QuotaType.choices,
default=QuotaType.UNLIMITED, verbose_name="配额模式")
Expand Down
Loading