Skip to content

fix: 任务差额结算后 quota 和阿里视频时长优化 - #5923

Merged
Calcium-Ion merged 2 commits into
QuantumNous:mainfrom
feitianbubu:pr/9f838d53f
Jul 6, 2026
Merged

fix: 任务差额结算后 quota 和阿里视频时长优化#5923
Calcium-Ion merged 2 commits into
QuantumNous:mainfrom
feitianbubu:pr/9f838d53f

Conversation

@feitianbubu

@feitianbubu feitianbubu commented Jul 6, 2026

Copy link
Copy Markdown
Member

⚠️ 提交说明 / PR Notice

Important

  • 请提供人工撰写的简洁摘要,避免直接粘贴未经整理的 AI 输出。

📝 变更描述 / Description

两个小修复:

  1. 异步任务完成后按实际用量差额结算时(RecalculateTaskQuota),之前只更新了内存里的 task 对象,没有写回数据库,导致任务列表里显示的 quota 和消费日志对不上(延迟结算的模型会一直显示 0)。补了一个单列回写 UpdateQuota(),只更新 quota 列,不碰状态列,避免和 UpdateWithStatus 的 CAS 冲突。
  2. 阿里视频任务的时长参数传 0 或负数时,现在会落到默认 5 秒,和不传时的行为保持一致。

🚀 变更类型 / Type of change

  • 🐛 Bug 修复 (Bug fix) - 请关联对应 Issue,避免将设计取舍、理解偏差或预期不一致直接归类为 bug
  • ✨ 新功能 (New feature) - 重大特性建议先通过 Issue 沟通
  • ⚡ 性能优化 / 重构 (Refactor)
  • 📝 文档更新 (Documentation)

🔗 关联任务 / Related Issue

✅ 提交前检查项 / Checklist

  • 人工确认: 我已亲自整理并撰写此描述,没有直接粘贴未经处理的 AI 输出。
  • 非重复提交: 我已搜索现有的 IssuesPRs,确认不是重复提交。
  • Bug fix 说明: 若此 PR 标记为 Bug fix,我已提交或关联对应 Issue,且不会将设计取舍、预期不一致或理解偏差直接归类为 bug。
  • 变更理解: 我已理解这些更改的工作原理及可能影响。
  • 范围聚焦: 本 PR 未包含任何与当前任务无关的代码改动。
  • 本地验证: 已在本地运行并通过测试或手动验证,维护者可以据此复核结果。
  • 安全合规: 代码中无敏感凭据,且符合项目代码规范。

📸 运行证明 / Proof of Work

实际环境复现:任务成功完成后消费日志有结算金额,但任务列表 quota 显示 0;修复后结算金额正常写回任务记录,与日志一致。构建通过。

Summary by CodeRabbit

  • Bug Fixes
    • Task quota updates are now saved immediately, improving billing accuracy and keeping task balances in sync.
    • Task duration handling now falls back to a safe default when provided values are missing, zero, or invalid, preventing unexpected scheduling behavior.

@coderabbitai

coderabbitai Bot commented Jul 6, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

Walkthrough

Adds a Task.UpdateQuota() method that persists only the quota column, wires it into RecalculateTaskQuota to write back recalculated quota with error logging, and adjusts the Ali task adaptor's duration fallback to apply the default whenever the parsed duration is non-positive rather than only when unset.

Changes

Task Quota Persistence

Layer / File(s) Summary
UpdateQuota method and billing integration
model/task.go, service/task_billing.go
Adds Task.UpdateQuota() to update only the quota column via GORM, and calls it from RecalculateTaskQuota after setting task.Quota, logging an error on failure.

Ali Adaptor Duration Fallback

Layer / File(s) Summary
Duration fallback logic
relay/channel/task/ali/adaptor.go
Changes default duration handling to apply fallback of 5 whenever computed Duration is <= 0, instead of only when unset.

Estimated code review effort: 1 (Trivial) | ~5 minutes

Possibly related PRs

  • QuantumNous/new-api#2985: Both PRs modify how RecalculateTaskQuota in service/task_billing.go persists updated task.Quota.

Poem

A quota hopped, now saved with care,
UpdateQuota writes it fair and square.
Ali's durations, once stuck at naught,
Now fallback five when zero's caught.
🐇 Thump-thump, the ledger's tight!

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed 标题准确概括了任务结算后 quota 持久化和阿里视频时长默认值修复。
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@feitianbubu feitianbubu changed the title fix: 任务差额结算后 quota 未写回任务记录 & 阿里视频时长默认值 fix: 任务差额结算后 quota 和阿里视频时长优化 Jul 6, 2026
@Calcium-Ion
Calcium-Ion merged commit 043720f into QuantumNous:main Jul 6, 2026
2 checks passed
52assert added a commit to 52assert/new-api that referenced this pull request Jul 7, 2026
…codes

* origin/main: (180 commits)
  fix(billing): extend quantity validation and saturating conversions to remaining paths
  fix(billing): validate quantity parameters and harden quota calculations
  Fix/build date dns error (QuantumNous#5945)
  fix: avoid stale stream writes after client disconnect (QuantumNous#5710)
  feat(group): enhance group ratio editor with improved visibility rules and JSON parsing
  feat: optimize legacy top-up warning banner copy (QuantumNous#5851) (QuantumNous#5855)
  fix(web): redirect authenticated users away from sign-up page (QuantumNous#5910)
  feat(ssrf): implement SSRF protection in HTTP clients and validation functions
  feat(user): better messages for redeem failures
  fix(html): 修复 Shadow DOM 隔离渲染下深浅色模式无法自动切换的问题 (QuantumNous#5890)
  fix(web): sync home iframe theme and language (QuantumNous#5917)
  fix: 任务差额结算后 quota 和阿里视频时长优化 (QuantumNous#5923)
  fix(web): refine mobile user cards
  test(user): cover self-service password update guard
  feat(session): support opt-in Secure session cookies
  fix(auth): allow read-only access for non-disabled tokens
  fix(user): harden account email and password handling
  fix: align dynamic pricing style with log details dialog sections
  fix(channels): show field passthrough controls for Codex (QuantumNous#5902)
  fix(user): trim whitespace from username and validate input
  ...

# Conflicts:
#	controller/redemption.go
#	controller/user.go
#	model/option.go
#	model/redemption.go
#	model/user.go
#	web/default/src/features/auth/api.ts
#	web/default/src/features/redemption-codes/api.ts
#	web/default/src/features/redemption-codes/components/redemptions-provider.tsx
#	web/default/src/features/redemption-codes/components/redemptions-table.tsx
#	web/default/src/features/redemption-codes/constants.ts
#	web/default/src/hooks/use-sidebar-data.ts
#	web/default/src/i18n/static-keys.ts
#	web/default/src/routes/__root.tsx
liulixin-lex pushed a commit to liulixin-lex/xy-api that referenced this pull request Jul 7, 2026
* fix: apply default ali video duration when value is non-positive

* fix: persist task quota after async settlement
YuanQianQ pushed a commit to YuanQianQ/new-api that referenced this pull request Jul 7, 2026
* fix: apply default ali video duration when value is non-positive

* fix: persist task quota after async settlement
quqi1599 pushed a commit to rebecca554owen/new-api that referenced this pull request Jul 7, 2026
* fix: apply default ali video duration when value is non-positive

* fix: persist task quota after async settlement
@coderabbitai coderabbitai Bot mentioned this pull request Jul 10, 2026
11 tasks
xiaomingchen pushed a commit to xiaomingchen/new-api that referenced this pull request Jul 10, 2026
* fix: apply default ali video duration when value is non-positive

* fix: persist task quota after async settlement
Jacobinwwey pushed a commit to Jacobinwwey/new-api that referenced this pull request Jul 11, 2026
* fix: apply default ali video duration when value is non-positive

* fix: persist task quota after async settlement
ruanhangjian pushed a commit to ruanhangjian/new-api that referenced this pull request Jul 11, 2026
* fix: apply default ali video duration when value is non-positive

* fix: persist task quota after async settlement
noah-wung pushed a commit to noah-wung/new-api that referenced this pull request Jul 17, 2026
* fix: apply default ali video duration when value is non-positive

* fix: persist task quota after async settlement
zhaodechao2008 pushed a commit to zhaodechao2008/new-api that referenced this pull request Jul 27, 2026
* fix: apply default ali video duration when value is non-positive

* fix: persist task quota after async settlement
330079598 pushed a commit to 330079598/new-api that referenced this pull request Aug 19, 2026
* fix: apply default ali video duration when value is non-positive

* fix: persist task quota after async settlement
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants