Repository navigation
Go: refactor UUID functions - #16695
Conversation
Signed-off-by: Jin Hai <[email protected]>
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
📝 WalkthroughWalkthroughThis PR standardizes ID and token generation across many DAO and service paths, changes beta API token generation to a no-argument form, removes several local UUID helpers, and makes one SSE error-scope adjustment. ChangesToken and ID generation standardization
Estimated code review effort: 2 (Simple) | ~15 minutes Possibly related PRs
Suggested labels: Suggested reviewers: Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 inconclusive)
✅ Passed checks (4 passed)
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. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🧹 Nitpick comments (2)
internal/utility/token.go (1)
144-144: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low value
GenerateToken32is identical toGenerateToken; the[:32]slice is a no-op.A canonical UUID string is 36 characters; removing the 4 hyphens always yields exactly 32 characters, so
[:32]never truncates anything. This makesGenerateToken32()behaviorally identical toGenerateToken()(line 141), and the32suffix/slice misleadingly implies a length constraint that isn't being enforced.Consider dropping the redundant slice and delegating to avoid duplication.
♻️ Suggested simplification
-func GenerateToken32() string { return strings.ReplaceAll(uuid.New().String(), "-", "")[:32] } +func GenerateToken32() string { return GenerateToken() }🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@internal/utility/token.go` at line 144, GenerateToken32 is redundant because it produces the same result as GenerateToken, since removing hyphens from uuid.New().String() already yields 32 characters and the [:32] slice does nothing. Update GenerateToken32 to delegate to GenerateToken (or otherwise reuse the shared logic) so the behavior is explicit and the duplication is removed, keeping the unique symbols GenerateToken32 and GenerateToken aligned.internal/service/api_token.go (1)
84-87: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low valueStale comment: beta is no longer derived from the API key.
The comment on line 86 still describes the old derivation (
generate_confirmation_token().replace("ragflow-", "")[:32]), butGenerateBetaAPIToken()now generates an independent random token unrelated toAPIToken. Update the comment to avoid confusion.🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@internal/service/api_token.go` around lines 84 - 87, The comment above GenerateBetaAPIToken in api_token.go is stale and still describes the old derivation from the API key. Update the beta comment to match the current behavior of APIToken and betaAPIKey, making it clear that GenerateBetaAPIToken now creates an independent random token unrelated to APIToken.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@internal/dao/file.go`:
- Around line 512-517: The addFileFromKB flow creates the entity.File before
inserting the File2Document mapping, but the failure path after DB.Create(f2d)
currently returns without removing the newly created file. Update the
addFileFromKB logic in internal/dao/file.go so that when the File2Document
insert fails, it deletes the File row before returning, matching the cleanup
behavior used in internal/service/document.go. Use the existing file variable
and the mapping insert path around DB.Create(f2d) to locate the fix.
---
Nitpick comments:
In `@internal/service/api_token.go`:
- Around line 84-87: The comment above GenerateBetaAPIToken in api_token.go is
stale and still describes the old derivation from the API key. Update the beta
comment to match the current behavior of APIToken and betaAPIKey, making it
clear that GenerateBetaAPIToken now creates an independent random token
unrelated to APIToken.
In `@internal/utility/token.go`:
- Line 144: GenerateToken32 is redundant because it produces the same result as
GenerateToken, since removing hyphens from uuid.New().String() already yields 32
characters and the [:32] slice does nothing. Update GenerateToken32 to delegate
to GenerateToken (or otherwise reuse the shared logic) so the behavior is
explicit and the duplication is removed, keeping the unique symbols
GenerateToken32 and GenerateToken aligned.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: c88ee0b7-2fda-4afa-a063-566d20f9e729
📒 Files selected for processing (14)
internal/admin/service.gointernal/agent/canvas/runner.gointernal/dao/connector.gointernal/dao/file.gointernal/entity/models/302ai.gointernal/service/agent.gointernal/service/agent_sessions.gointernal/service/api_token.gointernal/service/chat_session.gointernal/service/dataset.gointernal/service/deep_researcher.gointernal/service/document.gointernal/service/file.gointernal/utility/token.go
| docLocation = *doc.Location | ||
| } | ||
|
|
||
| fileID := generateUUID() | ||
| fileID := utility.GenerateToken() | ||
| file := &entity.File{ | ||
| ID: fileID, |
There was a problem hiding this comment.
🗄️ Data Integrity & Integration | 🟠 Major | ⚡ Quick win
🧩 Analysis chain
🏁 Script executed:
#!/bin/bash
set -euo pipefail
# Inspect the relevant sections with line numbers.
git ls-files internal/dao/file.go internal/service/document.go
wc -l internal/dao/file.go internal/service/document.go
sed -n '470,560p' internal/dao/file.go
printf '\n--- sibling ---\n'
sed -n '3340,3405p' internal/service/document.go
# Search for related create/delete patterns.
rg -n "Create\\(f2d\\)|Create\\(file\\)|Unscoped\\(\\).*Delete\\(&entity\\.File\\{|addFileFromKB" internal/dao/file.go internal/service/document.goRepository: infiniflow/ragflow
Length of output: 5470
🏁 Script executed:
#!/bin/bash
set -euo pipefail
# Inspect the DAO call site and any surrounding transaction handling.
sed -n '420,455p' internal/dao/file.go
printf '\n--- nearby DAO helpers ---\n'
sed -n '180,230p' internal/dao/file.go
printf '\n--- delete helper area ---\n'
sed -n '320,345p' internal/dao/file.go
# Look for any explicit transaction usage around the knowledgebase import path.
rg -n "Transaction\\(|Begin\\(|Commit\\(|Rollback\\(|addFileFromKB\\(" internal/dao internal/service | sed -n '1,120p'Repository: infiniflow/ragflow
Length of output: 7703
Clean up the File row if File2Document insert fails.
addFileFromKB creates the entity.File row before the mapping row, but on DB.Create(f2d) error it returns immediately without deleting the file. That leaves orphaned files behind and makes retries create duplicate file rows instead of completing the link. The sibling internal/service/document.go path already deletes the file on this failure path.
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
In `@internal/dao/file.go` around lines 512 - 517, The addFileFromKB flow creates
the entity.File before inserting the File2Document mapping, but the failure path
after DB.Create(f2d) currently returns without removing the newly created file.
Update the addFileFromKB logic in internal/dao/file.go so that when the
File2Document insert fails, it deletes the File row before returning, matching
the cleanup behavior used in internal/service/document.go. Use the existing file
variable and the mapping insert path around DB.Create(f2d) to locate the fix.
Signed-off-by: Jin Hai <[email protected]>
Signed-off-by: Jin Hai <[email protected]>
Signed-off-by: Jin Hai <[email protected]>
As title