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.

Add a db consistency check to remove runners that do not belong to a repository (#30614)

Follow #30406

(cherry picked from commit 30dd4beeee631860c7dd393c341e9955997095a4)

authored by

Zettat123 and committed by
Earl Warren
168cb758 4f73382e

+30 -2
+24 -2
models/actions/runner.go
··· 270 270 // Only affect action runners were a owner ID is set, as actions runners 271 271 // could also be created on a repository. 272 272 return db.GetEngine(ctx).Table("action_runner"). 273 - Join("LEFT", "user", "`action_runner`.owner_id = `user`.id"). 273 + Join("LEFT", "`user`", "`action_runner`.owner_id = `user`.id"). 274 274 Where("`action_runner`.owner_id != ?", 0). 275 275 And(builder.IsNull{"`user`.id"}). 276 276 Count(new(ActionRunner)) ··· 279 279 func FixRunnersWithoutBelongingOwner(ctx context.Context) (int64, error) { 280 280 subQuery := builder.Select("`action_runner`.id"). 281 281 From("`action_runner`"). 282 - Join("LEFT", "user", "`action_runner`.owner_id = `user`.id"). 282 + Join("LEFT", "`user`", "`action_runner`.owner_id = `user`.id"). 283 283 Where(builder.Neq{"`action_runner`.owner_id": 0}). 284 284 And(builder.IsNull{"`user`.id"}) 285 285 b := builder.Delete(builder.In("id", subQuery)).From("`action_runner`") ··· 289 289 } 290 290 return res.RowsAffected() 291 291 } 292 + 293 + func CountRunnersWithoutBelongingRepo(ctx context.Context) (int64, error) { 294 + return db.GetEngine(ctx).Table("action_runner"). 295 + Join("LEFT", "`repository`", "`action_runner`.repo_id = `repository`.id"). 296 + Where("`action_runner`.repo_id != ?", 0). 297 + And(builder.IsNull{"`repository`.id"}). 298 + Count(new(ActionRunner)) 299 + } 300 + 301 + func FixRunnersWithoutBelongingRepo(ctx context.Context) (int64, error) { 302 + subQuery := builder.Select("`action_runner`.id"). 303 + From("`action_runner`"). 304 + Join("LEFT", "`repository`", "`action_runner`.repo_id = `repository`.id"). 305 + Where(builder.Neq{"`action_runner`.repo_id": 0}). 306 + And(builder.IsNull{"`repository`.id"}) 307 + b := builder.Delete(builder.In("id", subQuery)).From("`action_runner`") 308 + res, err := db.GetEngine(ctx).Exec(b) 309 + if err != nil { 310 + return 0, err 311 + } 312 + return res.RowsAffected() 313 + }
+6
services/doctor/dbconsistency.go
··· 160 160 FixedMessage: "Removed", 161 161 }, 162 162 { 163 + Name: "Action Runners without existing repository", 164 + Counter: actions_model.CountRunnersWithoutBelongingRepo, 165 + Fixer: actions_model.FixRunnersWithoutBelongingRepo, 166 + FixedMessage: "Removed", 167 + }, 168 + { 163 169 Name: "Topics with empty repository count", 164 170 Counter: repo_model.CountOrphanedTopics, 165 171 Fixer: repo_model.DeleteOrphanedTopics,