From 6abfa48c0ecb9f19cb5b6c66763dbd577ac21dcc Mon Sep 17 00:00:00 2001
From: Ethan Koenig <ethantkoenig@gmail.com>
Date: Sun, 17 Dec 2017 03:53:02 -0800
Subject: [PATCH] Remove unnecessary updates to issue indexer (#3212)

---
 models/issue.go           |  2 +-
 models/issue_indexer.go   | 20 ++++++++++++++++++++
 models/issue_milestone.go |  2 +-
 3 files changed, 22 insertions(+), 2 deletions(-)

diff --git a/models/issue.go b/models/issue.go
index 7cea3b92a2..984e6e31cf 100644
--- a/models/issue.go
+++ b/models/issue.go
@@ -582,7 +582,7 @@ func updateIssueCols(e Engine, issue *Issue, cols ...string) error {
 	if _, err := e.ID(issue.ID).Cols(cols...).Update(issue); err != nil {
 		return err
 	}
-	UpdateIssueIndexer(issue.ID)
+	UpdateIssueIndexerCols(issue.ID, cols...)
 	return nil
 }
 
diff --git a/models/issue_indexer.go b/models/issue_indexer.go
index c50b733492..3a2ad157c3 100644
--- a/models/issue_indexer.go
+++ b/models/issue_indexer.go
@@ -102,6 +102,26 @@ func (issue *Issue) update() indexer.IssueIndexerUpdate {
 	}
 }
 
+// updateNeededCols whether a change to the specified columns requires updating
+// the issue indexer
+func updateNeededCols(cols []string) bool {
+	for _, col := range cols {
+		switch col {
+		case "name", "content":
+			return true
+		}
+	}
+	return false
+}
+
+// UpdateIssueIndexerCols update an issue in the issue indexer, given changes
+// to the specified columns
+func UpdateIssueIndexerCols(issueID int64, cols ...string) {
+	if updateNeededCols(cols) {
+		UpdateIssueIndexer(issueID)
+	}
+}
+
 // UpdateIssueIndexer add/update an issue to the issue indexer
 func UpdateIssueIndexer(issueID int64) {
 	select {
diff --git a/models/issue_milestone.go b/models/issue_milestone.go
index b4ebabf57e..6ec8291233 100644
--- a/models/issue_milestone.go
+++ b/models/issue_milestone.go
@@ -282,7 +282,7 @@ func changeMilestoneAssign(e *xorm.Session, doer *User, issue *Issue, oldMilesto
 		}
 	}
 
-	return updateIssue(e, issue)
+	return updateIssueCols(e, issue, "milestone_id")
 }
 
 // ChangeMilestoneAssign changes assignment of milestone for issue.