loading up the forgejo repo on tangled to test page performance
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

Fix topics deleted via API not being deleted in org page (#24825)

The topics are saved in the `repo_topic` table.
They are also saved directly in the `repository` table.

Before this PR, only `AddTopic` and `SaveTopics` made sure the `topics`
field in the `repository` table was synced with the `repo_topic` table.

This PR makes sure `GenerateTopics` and `DeleteTopic`
also sync the `topics` in the repository table.

`RemoveTopicsFromRepo` doesn't need to sync the data
as it is only used to delete a repository.

Fixes #24820

authored by

Yarden Shoham and committed by
GitHub
edd8ea0b 1dfaf837

+25 -20
+25 -20
models/repo/topic.go
··· 253 253 return nil, err 254 254 } 255 255 256 - topicNames := make([]string, 0, 25) 257 - if err := sess.Select("name").Table("topic"). 258 - Join("INNER", "repo_topic", "repo_topic.topic_id = topic.id"). 259 - Where("repo_topic.repo_id = ?", repoID).Desc("topic.repo_count").Find(&topicNames); err != nil { 260 - return nil, err 261 - } 262 - 263 - if _, err := sess.ID(repoID).Cols("topics").Update(&Repository{ 264 - Topics: topicNames, 265 - }); err != nil { 256 + if err = syncTopicsInRepository(sess, repoID); err != nil { 266 257 return nil, err 267 258 } 268 259 ··· 281 272 } 282 273 283 274 err = removeTopicFromRepo(db.DefaultContext, repoID, topic) 275 + if err != nil { 276 + return nil, err 277 + } 278 + 279 + err = syncTopicsInRepository(db.GetEngine(db.DefaultContext), repoID) 284 280 285 281 return topic, err 286 282 } ··· 347 343 } 348 344 } 349 345 350 - topicNames = make([]string, 0, 25) 351 - if err := sess.Table("topic").Cols("name"). 352 - Join("INNER", "repo_topic", "repo_topic.topic_id = topic.id"). 353 - Where("repo_topic.repo_id = ?", repoID).Desc("topic.repo_count").Find(&topicNames); err != nil { 354 - return err 355 - } 356 - 357 - if _, err := sess.ID(repoID).Cols("topics").Update(&Repository{ 358 - Topics: topicNames, 359 - }); err != nil { 346 + if err := syncTopicsInRepository(sess, repoID); err != nil { 360 347 return err 361 348 } 362 349 ··· 369 356 if _, err := addTopicByNameToRepo(ctx, generateRepo.ID, topic); err != nil { 370 357 return err 371 358 } 359 + } 360 + 361 + return syncTopicsInRepository(db.GetEngine(ctx), generateRepo.ID) 362 + } 363 + 364 + // syncTopicsInRepository makes sure topics in the topics table are copied into the topics field of the repository 365 + func syncTopicsInRepository(sess db.Engine, repoID int64) error { 366 + topicNames := make([]string, 0, 25) 367 + if err := sess.Table("topic").Cols("name"). 368 + Join("INNER", "repo_topic", "repo_topic.topic_id = topic.id"). 369 + Where("repo_topic.repo_id = ?", repoID).Desc("topic.repo_count").Find(&topicNames); err != nil { 370 + return err 371 + } 372 + 373 + if _, err := sess.ID(repoID).Cols("topics").Update(&Repository{ 374 + Topics: topicNames, 375 + }); err != nil { 376 + return err 372 377 } 373 378 return nil 374 379 }