@@ -129,7 +129,7 @@ func addTopicByNameToRepo(e Engine, repoID int64, topicName string) (*Topic, err
129129}
130130
131131// removeTopicFromRepo remove a topic from a repo and decrements the topic repo count
132- func removeTopicFromRepo (repoID int64 , topic * Topic , e Engine ) error {
132+ func removeTopicFromRepo (e Engine , repoID int64 , topic * Topic ) error {
133133 topic .RepoCount --
134134 if _ , err := e .ID (topic .ID ).Cols ("repo_count" ).Update (topic ); err != nil {
135135 return err
@@ -145,6 +145,24 @@ func removeTopicFromRepo(repoID int64, topic *Topic, e Engine) error {
145145 return nil
146146}
147147
148+ // removeTopicsFromRepo remove all topics from the repo and decrements respective topics repo count
149+ func removeTopicsFromRepo (e Engine , repoID int64 ) error {
150+ _ , err := e .Where (
151+ builder .In ("id" ,
152+ builder .Select ("topic_id" ).From ("repo_topic" ).Where (builder.Eq {"repo_id" : repoID }),
153+ ),
154+ ).Cols ("repo_count" ).SetExpr ("repo_count" , "repo_count-1" ).Update (& Topic {})
155+ if err != nil {
156+ return err
157+ }
158+
159+ if _ , err = e .Delete (& RepoTopic {RepoID : repoID }); err != nil {
160+ return err
161+ }
162+
163+ return nil
164+ }
165+
148166// FindTopicOptions represents the options when fdin topics
149167type FindTopicOptions struct {
150168 ListOptions
@@ -216,7 +234,7 @@ func DeleteTopic(repoID int64, topicName string) (*Topic, error) {
216234 return nil , nil
217235 }
218236
219- err = removeTopicFromRepo (repoID , topic , x )
237+ err = removeTopicFromRepo (x , repoID , topic )
220238
221239 return topic , err
222240}
@@ -277,7 +295,7 @@ func SaveTopics(repoID int64, topicNames ...string) error {
277295 }
278296
279297 for _ , topic := range removeTopics {
280- err := removeTopicFromRepo (repoID , topic , sess )
298+ err := removeTopicFromRepo (sess , repoID , topic )
281299 if err != nil {
282300 return err
283301 }
0 commit comments