Added update query for correct topics count

Signed-off-by: Alexey Terentyev <axifnx@gmail.com>
This commit is contained in:
Alexey Terentyev 2018-06-22 21:20:15 +03:00
parent 7ee9774cea
commit 0ceee66fee
No known key found for this signature in database
GPG Key ID: 60D6C550AEEBB467

View File

@ -60,7 +60,7 @@ func reformatAndRemoveIncorrectTopics(x *xorm.Engine) (err error) {
if models.ValidateTopic(topic.Name) {
unifiedTopic := Topic{Name:topic.Name}
exists, err := sess.Get(&unifiedTopic)
log.Info("Exists topic with the name %q? %v id = %v", topic.Name, exists, unifiedTopic.ID)
log.Info("Exists topic with the name %q? %v, id = %v", topic.Name, exists, unifiedTopic.ID)
if err != nil {
return err
}
@ -72,6 +72,12 @@ func reformatAndRemoveIncorrectTopics(x *xorm.Engine) (err error) {
topic.ID, topic.ID, unifiedTopic.ID).Update(&models.RepoTopic{TopicID:unifiedTopic.ID}); err != nil {
return err
}
log.Info("Updating topic `repo_count` field")
if _, err := sess.Exec(
"UPDATE topic SET repo_count = (SELECT COUNT(*) FROM repo_topic WHERE topic_id = ? GROUP BY topic_id) WHERE id = ?",
unifiedTopic.ID, unifiedTopic.ID); err != nil {
return err
}
} else {
log.Info("Updating topic: id = %v, name = %q", topic.ID, topic.Name)
if _, err := sess.Table("topic").ID(topic.ID).