Added query solution for duplicates

Signed-off-by: Alexey Terentyev <axifnx@gmail.com>
This commit is contained in:
Alexey Terentyev 2018-06-18 05:25:26 +03:00
parent 8fee5d3f64
commit 9141482afd
No known key found for this signature in database
GPG Key ID: 60D6C550AEEBB467
2 changed files with 8 additions and 1 deletions

View File

@ -129,7 +129,7 @@ func reformatAndRemoveIncorrectTopics(x *xorm.Engine) (err error) {
}
log.Info("Updating 'topics' field for repository with id = %v", repoID)
if _, err := sess.ID(repoID).Cols("topics").
Update(&models.Repository{ID: repoID, Topics: topicNames}); err != nil {
Update(&models.Repository{Topics: topicNames}); err != nil {
return err
}
}

View File

@ -190,6 +190,13 @@ func SaveTopics(repoID int64, topicNames ...string) error {
}
}
topicNames = topicNames[:0]
if err := sess.Table("topic").Cols("name").
Join("INNER", "repo_topic", "topic.id = repo_topic.topic_id").
Where("repo_topic.repo_id = ?", repoID).Find(&topicNames); err != nil {
return err
}
if _, err := sess.ID(repoID).Cols("topics").Update(&Repository{
Topics: topicNames,
}); err != nil {