From 9972bee41f3c6ca493a5b82afaa0f0ebce462c1d Mon Sep 17 00:00:00 2001 From: Giteabot Date: Sun, 26 Jul 2026 06:20:17 -0700 Subject: [PATCH] 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 Co-authored-by: Elisei Roca Co-authored-by: wxiaoguang --- models/issues/comment.go | 7 +++++-- models/issues/comment_list.go | 2 +- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/models/issues/comment.go b/models/issues/comment.go index 40fa9997506..0307bb42da1 100644 --- a/models/issues/comment.go +++ b/models/issues/comment.go @@ -544,6 +544,9 @@ func (c *Comment) GetSanitizedContentHTML() template.HTML { // LoadLabel if comment.Type is CommentTypeLabel, then load Label func (c *Comment) LoadLabel(ctx context.Context) error { + if c.LabelID == 0 { + return nil + } var label Label has, err := db.GetEngine(ctx).ID(c.LabelID).Get(&label) if err != nil { @@ -551,8 +554,8 @@ func (c *Comment) LoadLabel(ctx context.Context) error { } else if has { c.Label = &label } else { - // Ignore Label is deleted, but not clear this table - log.Warn("Commit %d cannot load label %d", c.ID, c.LabelID) + // label was deleted but comment rows referencing it were not cleaned up + log.Debug("Comment %d references deleted label %d", c.ID, c.LabelID) } return nil diff --git a/models/issues/comment_list.go b/models/issues/comment_list.go index 610bd16f5a0..495d48ff44b 100644 --- a/models/issues/comment_list.go +++ b/models/issues/comment_list.go @@ -81,7 +81,7 @@ func (comments CommentList) loadLabels(ctx context.Context) error { } for _, comment := range comments { - comment.Label = commentLabels[comment.ID] + comment.Label = commentLabels[comment.LabelID] } return nil }