Skip to content

fix: remove duplicate Id in GeneralDelDto.GetIds()#848

Open
KiwiGaze wants to merge 1 commit intogo-admin-team:masterfrom
KiwiGaze:fix/general-del-dto-duplicate-id
Open

fix: remove duplicate Id in GeneralDelDto.GetIds()#848
KiwiGaze wants to merge 1 commit intogo-admin-team:masterfrom
KiwiGaze:fix/general-del-dto-duplicate-id

Conversation

@KiwiGaze
Copy link
Copy Markdown

@KiwiGaze KiwiGaze commented Mar 22, 2026

[中文版模板 / Chinese template]

🤔 This is a ...

  • New feature
  • Bug fix
  • Site / documentation update
  • Demo update
  • Component style update
  • TypeScript definition update
  • Bundle size optimization
  • Performance optimization
  • Enhancement feature
  • Internationalization
  • Refactoring
  • Code style optimization
  • Test Case
  • Branch merge
  • Other (about what?)

🔗 Related issue link

No existing issue — discovered via code review.

💡 Background and solution

GeneralDelDto.GetIds() appends g.Id twice when g.Ids is empty and g.Id > 0:

// Before: g.Id=5, g.Ids=[] → returns [5, 5]
if g.Id != 0 {
    ids = append(ids, g.Id)  // first append
}
if len(g.Ids) > 0 {
    // skipped when Ids is empty
} else {
    if g.Id > 0 {
        ids = append(ids, g.Id)  // duplicate append
    }
}

Simplified to a single linear pass that collects g.Id (if positive), then all positive entries from g.Ids, preserving the existing safety guard that appends 0 when the result is empty (to prevent full-table deletes):

// After: g.Id=5, g.Ids=[] → returns [5]
if g.Id > 0 {
    ids = append(ids, g.Id)
}
for _, id := range g.Ids {
    if id > 0 {
        ids = append(ids, id)
    }
}

📝 Changelog

Language Changelog
🇺🇸 English Fix duplicate Id in GeneralDelDto.GetIds() when Ids slice is empty
🇨🇳 Chinese 修复 GeneralDelDto.GetIds()Ids 为空时重复添加 Id 的问题

☑️ Self-Check before Merge

⚠️ Please check all items below before review. ⚠️

  • Doc is updated/provided or not needed
  • Demo is updated/provided or not needed
  • TypeScript's definition is updated/provided or not needed
  • Changelog is provided or not needed

When g.Ids is empty and g.Id > 0, the Id was appended twice:
once by the initial `if g.Id != 0` check and again in the
`else` branch. Simplified to a single pass that collects g.Id
and g.Ids without branching, preserving the safety guard against
empty slices.
@KiwiGaze
Copy link
Copy Markdown
Author

@wenjianzhang Could you please review this fix? You authored the original code in common/dto/search.go. Thanks!

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.

1 participant