From 7ea7f2b37f746922fe45c2418827e99a9a3041a7 Mon Sep 17 00:00:00 2001 From: Giteabot Date: Fri, 29 Sep 2023 10:00:14 +0800 Subject: [PATCH] Add Index to `comment.dependent_issue_id` (#27325) (#27340) Backport #27325 by @JakobDev This Column is missing index. It is used by [issue_service.deleteIssue](https://github.com/go-gitea/gitea/blob/7ea2a910cebaf51cfd13c0941029c404e408ae54/services/issue/issue.go#L300). Co-authored-by: JakobDev --- models/issues/comment.go | 2 +- models/migrations/migrations.go | 2 ++ models/migrations/v1_21/v278.go | 16 ++++++++++++++++ 3 files changed, 19 insertions(+), 1 deletion(-) create mode 100644 models/migrations/v1_21/v278.go diff --git a/models/issues/comment.go b/models/issues/comment.go index 66b3a8527f..8b1b18051e 100644 --- a/models/issues/comment.go +++ b/models/issues/comment.go @@ -246,7 +246,7 @@ type Comment struct { NewTitle string OldRef string NewRef string - DependentIssueID int64 + DependentIssueID int64 `xorm:"index"` // This is used by issue_service.deleteIssue DependentIssue *Issue `xorm:"-"` CommitID int64 diff --git a/models/migrations/migrations.go b/models/migrations/migrations.go index 38fff37bed..4527bcc1ae 100644 --- a/models/migrations/migrations.go +++ b/models/migrations/migrations.go @@ -536,6 +536,8 @@ var migrations = []Migration{ NewMigration("Add RemoteAddress to mirrors", v1_21.AddRemoteAddressToMirrors), // v277 -> v278 NewMigration("Add Index to issue_user.issue_id", v1_21.AddIndexToIssueUserIssueID), + // v278 -> v279 + NewMigration("Add Index to comment.dependent_issue_id", v1_21.AddIndexToCommentDependentIssueID), } // GetCurrentDBVersion returns the current db version diff --git a/models/migrations/v1_21/v278.go b/models/migrations/v1_21/v278.go new file mode 100644 index 0000000000..d6a462d1e7 --- /dev/null +++ b/models/migrations/v1_21/v278.go @@ -0,0 +1,16 @@ +// Copyright 2023 The Gitea Authors. All rights reserved. +// SPDX-License-Identifier: MIT + +package v1_21 //nolint + +import ( + "xorm.io/xorm" +) + +func AddIndexToCommentDependentIssueID(x *xorm.Engine) error { + type Comment struct { + DependentIssueID int64 `xorm:"index"` + } + + return x.Sync(new(Comment)) +}