fix(issues): fix label bulk-load key and reduce log noise in LoadLabel (#38632) (#38643)

Backport #38632 by @eliroca

CommentList.loadLabels keyed the result map by label.ID but looked up by
comment.ID, so every label event fell back to individual DB queries.

This caused log spam for any comment where the label was deleted, since
ToTimelineComment calls LoadLabel unconditionally for all comment types
including those with LabelID=0.

Fix the map key, skip the query when LabelID=0, demote the now rarely
triggered orphaned-label log to Debug, and fix a typo ("Commit" ->
"Comment") in that message.

Signed-off-by: wxiaoguang <wxiaoguang@gmail.com>
Co-authored-by: Elisei Roca <eroca@suse.de>
Co-authored-by: wxiaoguang <wxiaoguang@gmail.com>
This commit is contained in:
Giteabot
2026-07-26 13:20:17 +00:00
committed by GitHub
co-authored by Elisei Roca wxiaoguang
parent 375e6ea038
commit 9972bee41f
2 changed files with 6 additions and 3 deletions
+5 -2
View File
@@ -544,6 +544,9 @@ func (c *Comment) GetSanitizedContentHTML() template.HTML {
// LoadLabel if comment.Type is CommentTypeLabel, then load Label // LoadLabel if comment.Type is CommentTypeLabel, then load Label
func (c *Comment) LoadLabel(ctx context.Context) error { func (c *Comment) LoadLabel(ctx context.Context) error {
if c.LabelID == 0 {
return nil
}
var label Label var label Label
has, err := db.GetEngine(ctx).ID(c.LabelID).Get(&label) has, err := db.GetEngine(ctx).ID(c.LabelID).Get(&label)
if err != nil { if err != nil {
@@ -551,8 +554,8 @@ func (c *Comment) LoadLabel(ctx context.Context) error {
} else if has { } else if has {
c.Label = &label c.Label = &label
} else { } else {
// Ignore Label is deleted, but not clear this table // label was deleted but comment rows referencing it were not cleaned up
log.Warn("Commit %d cannot load label %d", c.ID, c.LabelID) log.Debug("Comment %d references deleted label %d", c.ID, c.LabelID)
} }
return nil return nil
+1 -1
View File
@@ -81,7 +81,7 @@ func (comments CommentList) loadLabels(ctx context.Context) error {
} }
for _, comment := range comments { for _, comment := range comments {
comment.Label = commentLabels[comment.ID] comment.Label = commentLabels[comment.LabelID]
} }
return nil return nil
} }