Skip to content

Commit bcabe51

Browse files
committed
Improve filtering for push mirrors
1 parent eb25993 commit bcabe51

File tree

2 files changed

+14
-6
lines changed

2 files changed

+14
-6
lines changed

models/repo/pushmirror.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,15 @@ func GetPushMirrorsByRepoID(repoID int64) ([]*PushMirror, error) {
9494
return mirrors, db.GetEngine(db.DefaultContext).Where("repo_id=?", repoID).Find(&mirrors)
9595
}
9696

97+
// GetPushMirrorsByRepoIDWithSyncOnPush returns push-mirror information of a repository,
98+
// filtered by sync_on_push.
99+
func GetPushMirrorsByRepoIDWithSyncOnPush(repoID int64, syncOnPush bool) ([]*PushMirror, error) {
100+
mirrors := make([]*PushMirror, 0, 10)
101+
return mirrors, db.GetEngine(db.DefaultContext).
102+
Where("repo_id=? AND sync_on_push=?", repoID, syncOnPush).
103+
Find(&mirrors)
104+
}
105+
97106
// PushMirrorsIterate iterates all push-mirror repositories.
98107
func PushMirrorsIterate(limit int, f func(idx int, bean interface{}) error) error {
99108
return db.GetEngine(db.DefaultContext).

modules/notification/mirror/mirror.go

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -32,16 +32,15 @@ func (m *mirrorNotifier) NotifyPushCommits(pusher *user_model.User, repo *repo_m
3232
ctx, _, finished := process.GetManager().AddContext(graceful.GetManager().HammerContext(), fmt.Sprintf("mirrorNotifier.NotifyPushCommits User: %s[%d] in %s[%d]", pusher.Name, pusher.ID, repo.FullName(), repo.ID))
3333
defer finished()
3434

35-
pushMirrors, err := repo_model.GetPushMirrorsByRepoID(repo.ID)
35+
syncOnPush := true
36+
pushMirrors, err := repo_model.GetPushMirrorsByRepoIDWithSyncOnPush(repo.ID, syncOnPush)
3637
if err != nil {
37-
log.Error("repo_model.GetPushMirrorsByRepoID failed: %v", err)
38+
log.Error("repo_model.GetPushMirrorsByRepoIDWithSyncOnPush failed: %v", err)
3839
return
3940
}
4041

4142
for _, mirror := range pushMirrors {
42-
if mirror.SyncOnPush {
43-
// TODO: push mirror likely will benefit from using a queue
44-
pushmirror_service.SyncPushMirror(ctx, mirror.ID)
45-
}
43+
// TODO: push mirror likely will benefit from using a queue
44+
pushmirror_service.SyncPushMirror(ctx, mirror.ID)
4645
}
4746
}

0 commit comments

Comments
 (0)