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.

Move `modules/mirror` to `services` (#26737)

To solve the cyclic imports in a better way

Closes #20261

authored by

Chongyi Zheng and committed by
GitHub
43652746 37b3ba22

+32 -39
+1 -1
models/repo/pushmirror.go
··· 128 128 func GetPushMirrorsSyncedOnCommit(ctx context.Context, repoID int64) ([]*PushMirror, error) { 129 129 mirrors := make([]*PushMirror, 0, 10) 130 130 return mirrors, db.GetEngine(ctx). 131 - Where("repo_id=? AND sync_on_commit=?", repoID, true). 131 + Where("repo_id = ? AND sync_on_commit = ?", repoID, true). 132 132 Find(&mirrors) 133 133 } 134 134
modules/mirror/mirror.go services/mirror/queue.go
+5 -19
modules/notification/mirror/mirror.go services/mirror/notifier.go
··· 8 8 9 9 repo_model "code.gitea.io/gitea/models/repo" 10 10 user_model "code.gitea.io/gitea/models/user" 11 - "code.gitea.io/gitea/modules/log" 12 - mirror_module "code.gitea.io/gitea/modules/mirror" 11 + "code.gitea.io/gitea/modules/notification" 13 12 "code.gitea.io/gitea/modules/notification/base" 14 13 "code.gitea.io/gitea/modules/repository" 15 14 ) 16 15 16 + func init() { 17 + notification.RegisterNotifier(&mirrorNotifier{}) 18 + } 19 + 17 20 type mirrorNotifier struct { 18 21 base.NullNotifier 19 22 } 20 23 21 24 var _ base.Notifier = &mirrorNotifier{} 22 - 23 - // NewNotifier create a new mirrorNotifier notifier 24 - func NewNotifier() base.Notifier { 25 - return &mirrorNotifier{} 26 - } 27 25 28 26 func (m *mirrorNotifier) NotifyPushCommits(ctx context.Context, _ *user_model.User, repo *repo_model.Repository, _ *repository.PushUpdateOptions, _ *repository.PushCommits) { 29 27 syncPushMirrorWithSyncOnCommit(ctx, repo.ID) ··· 32 30 func (m *mirrorNotifier) NotifySyncPushCommits(ctx context.Context, _ *user_model.User, repo *repo_model.Repository, _ *repository.PushUpdateOptions, _ *repository.PushCommits) { 33 31 syncPushMirrorWithSyncOnCommit(ctx, repo.ID) 34 32 } 35 - 36 - func syncPushMirrorWithSyncOnCommit(ctx context.Context, repoID int64) { 37 - pushMirrors, err := repo_model.GetPushMirrorsSyncedOnCommit(ctx, repoID) 38 - if err != nil { 39 - log.Error("repo_model.GetPushMirrorsSyncedOnCommit failed: %v", err) 40 - return 41 - } 42 - 43 - for _, mirror := range pushMirrors { 44 - mirror_module.AddPushMirrorToQueue(mirror.ID) 45 - } 46 - }
-2
modules/notification/notification.go
··· 16 16 "code.gitea.io/gitea/modules/notification/base" 17 17 "code.gitea.io/gitea/modules/notification/indexer" 18 18 "code.gitea.io/gitea/modules/notification/mail" 19 - "code.gitea.io/gitea/modules/notification/mirror" 20 19 "code.gitea.io/gitea/modules/notification/ui" 21 20 "code.gitea.io/gitea/modules/repository" 22 21 "code.gitea.io/gitea/modules/setting" ··· 38 37 } 39 38 RegisterNotifier(indexer.NewNotifier()) 40 39 RegisterNotifier(action.NewNotifier()) 41 - RegisterNotifier(mirror.NewNotifier()) 42 40 } 43 41 44 42 // NotifyNewWikiPage notifies creating new wiki pages to notifiers
+1 -2
routers/api/v1/repo/mirror.go
··· 14 14 repo_model "code.gitea.io/gitea/models/repo" 15 15 "code.gitea.io/gitea/models/unit" 16 16 "code.gitea.io/gitea/modules/context" 17 - mirror_module "code.gitea.io/gitea/modules/mirror" 18 17 "code.gitea.io/gitea/modules/setting" 19 18 api "code.gitea.io/gitea/modules/structs" 20 19 "code.gitea.io/gitea/modules/util" ··· 70 69 return 71 70 } 72 71 73 - mirror_module.AddPullMirrorToQueue(repo.ID) 72 + mirror_service.AddPullMirrorToQueue(repo.ID) 74 73 75 74 ctx.Status(http.StatusOK) 76 75 }
+3 -4
routers/web/repo/setting/setting.go
··· 24 24 "code.gitea.io/gitea/modules/indexer/stats" 25 25 "code.gitea.io/gitea/modules/lfs" 26 26 "code.gitea.io/gitea/modules/log" 27 - mirror_module "code.gitea.io/gitea/modules/mirror" 28 27 repo_module "code.gitea.io/gitea/modules/repository" 29 28 "code.gitea.io/gitea/modules/setting" 30 29 "code.gitea.io/gitea/modules/structs" ··· 277 276 return 278 277 } 279 278 280 - mirror_module.AddPullMirrorToQueue(repo.ID) 279 + mirror_service.AddPullMirrorToQueue(repo.ID) 281 280 282 281 ctx.Flash.Info(ctx.Tr("repo.settings.mirror_sync_in_progress")) 283 282 ctx.Redirect(repo.Link() + "/settings") ··· 294 293 return 295 294 } 296 295 297 - mirror_module.AddPushMirrorToQueue(m.ID) 296 + mirror_service.AddPushMirrorToQueue(m.ID) 298 297 299 298 ctx.Flash.Info(ctx.Tr("repo.settings.mirror_sync_in_progress")) 300 299 ctx.Redirect(repo.Link() + "/settings") ··· 332 331 // If we observed its implementation in the context of `push-mirror-sync` where it 333 332 // is evident that pushing to the queue is necessary for updates. 334 333 // So, there are updates within the given interval, it is necessary to update the queue accordingly. 335 - mirror_module.AddPushMirrorToQueue(m.ID) 334 + mirror_service.AddPushMirrorToQueue(m.ID) 336 335 ctx.Flash.Success(ctx.Tr("repo.settings.update_settings_success")) 337 336 ctx.Redirect(repo.Link() + "/settings") 338 337
+10 -11
services/mirror/mirror.go
··· 10 10 repo_model "code.gitea.io/gitea/models/repo" 11 11 "code.gitea.io/gitea/modules/graceful" 12 12 "code.gitea.io/gitea/modules/log" 13 - mirror_module "code.gitea.io/gitea/modules/mirror" 14 13 "code.gitea.io/gitea/modules/queue" 15 14 "code.gitea.io/gitea/modules/setting" 16 15 ) 17 16 18 17 // doMirrorSync causes this request to mirror itself 19 - func doMirrorSync(ctx context.Context, req *mirror_module.SyncRequest) { 18 + func doMirrorSync(ctx context.Context, req *SyncRequest) { 20 19 if req.ReferenceID == 0 { 21 20 log.Warn("Skipping mirror sync request, no mirror ID was specified") 22 21 return 23 22 } 24 23 switch req.Type { 25 - case mirror_module.PushMirrorType: 24 + case PushMirrorType: 26 25 _ = SyncPushMirror(ctx, req.ReferenceID) 27 - case mirror_module.PullMirrorType: 26 + case PullMirrorType: 28 27 _ = SyncPullMirror(ctx, req.ReferenceID) 29 28 default: 30 29 log.Error("Unknown Request type in queue: %v for MirrorID[%d]", req.Type, req.ReferenceID) ··· 43 42 44 43 handler := func(idx int, bean any) error { 45 44 var repo *repo_model.Repository 46 - var mirrorType mirror_module.SyncType 45 + var mirrorType SyncType 47 46 var referenceID int64 48 47 49 48 if m, ok := bean.(*repo_model.Mirror); ok { ··· 52 51 return nil 53 52 } 54 53 repo = m.Repo 55 - mirrorType = mirror_module.PullMirrorType 54 + mirrorType = PullMirrorType 56 55 referenceID = m.RepoID 57 56 } else if m, ok := bean.(*repo_model.PushMirror); ok { 58 57 if m.GetRepository() == nil { ··· 60 59 return nil 61 60 } 62 61 repo = m.Repo 63 - mirrorType = mirror_module.PushMirrorType 62 + mirrorType = PushMirrorType 64 63 referenceID = m.ID 65 64 } else { 66 65 log.Error("Unknown bean: %v", bean) ··· 75 74 } 76 75 77 76 // Push to the Queue 78 - if err := mirror_module.PushToQueue(mirrorType, referenceID); err != nil { 77 + if err := PushToQueue(mirrorType, referenceID); err != nil { 79 78 if err == queue.ErrAlreadyInQueue { 80 - if mirrorType == mirror_module.PushMirrorType { 79 + if mirrorType == PushMirrorType { 81 80 log.Trace("PushMirrors for %-v already queued for sync", repo) 82 81 } else { 83 82 log.Trace("PullMirrors for %-v already queued for sync", repo) ··· 120 119 return nil 121 120 } 122 121 123 - func queueHandler(items ...*mirror_module.SyncRequest) []*mirror_module.SyncRequest { 122 + func queueHandler(items ...*SyncRequest) []*SyncRequest { 124 123 for _, req := range items { 125 124 doMirrorSync(graceful.GetManager().ShutdownContext(), req) 126 125 } ··· 129 128 130 129 // InitSyncMirrors initializes a go routine to sync the mirrors 131 130 func InitSyncMirrors() { 132 - mirror_module.StartSyncMirrors(queueHandler) 131 + StartSyncMirrors(queueHandler) 133 132 }
+12
services/mirror/mirror_push.go
··· 253 253 254 254 return nil 255 255 } 256 + 257 + func syncPushMirrorWithSyncOnCommit(ctx context.Context, repoID int64) { 258 + pushMirrors, err := repo_model.GetPushMirrorsSyncedOnCommit(ctx, repoID) 259 + if err != nil { 260 + log.Error("repo_model.GetPushMirrorsSyncedOnCommit failed: %v", err) 261 + return 262 + } 263 + 264 + for _, mirror := range pushMirrors { 265 + AddPushMirrorToQueue(mirror.ID) 266 + } 267 + }