@@ -129,7 +129,7 @@ func addTopicByNameToRepo(e Engine, repoID int64, topicName string) (*Topic, err
129
129
}
130
130
131
131
// 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 {
133
133
topic .RepoCount --
134
134
if _ , err := e .ID (topic .ID ).Cols ("repo_count" ).Update (topic ); err != nil {
135
135
return err
@@ -145,6 +145,24 @@ func removeTopicFromRepo(repoID int64, topic *Topic, e Engine) error {
145
145
return nil
146
146
}
147
147
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
+
148
166
// FindTopicOptions represents the options when fdin topics
149
167
type FindTopicOptions struct {
150
168
ListOptions
@@ -216,7 +234,7 @@ func DeleteTopic(repoID int64, topicName string) (*Topic, error) {
216
234
return nil , nil
217
235
}
218
236
219
- err = removeTopicFromRepo (repoID , topic , x )
237
+ err = removeTopicFromRepo (x , repoID , topic )
220
238
221
239
return topic , err
222
240
}
@@ -277,7 +295,7 @@ func SaveTopics(repoID int64, topicNames ...string) error {
277
295
}
278
296
279
297
for _ , topic := range removeTopics {
280
- err := removeTopicFromRepo (repoID , topic , sess )
298
+ err := removeTopicFromRepo (sess , repoID , topic )
281
299
if err != nil {
282
300
return err
283
301
}
0 commit comments