-
-
Notifications
You must be signed in to change notification settings - Fork 5.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use conditions but not repo ids as query condition (#16839)
* Use conditions but not repo ids as query condition * Improve the performance of pulls/issue * Remove duplicated code * fix lint * Fix bug * Fix stats * More fixes * Fix build * Fix lint * Fix test * Fix build * Adjust the logic * Merge * Fix conflicts * improve the performance * Add comments for the query conditions functions * Some improvements
- Loading branch information
Showing
11 changed files
with
397 additions
and
423 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
// Copyright 2021 The Gitea Authors. All rights reserved. | ||
// Use of this source code is governed by a MIT-style | ||
// license that can be found in the LICENSE file. | ||
|
||
package repo | ||
|
||
import ( | ||
"code.gitea.io/gitea/models/db" | ||
"code.gitea.io/gitea/modules/setting" | ||
) | ||
|
||
// GetUserMirrorRepositories returns a list of mirror repositories of given user. | ||
func GetUserMirrorRepositories(userID int64) ([]*Repository, error) { | ||
repos := make([]*Repository, 0, 10) | ||
return repos, db.GetEngine(db.DefaultContext). | ||
Where("owner_id = ?", userID). | ||
And("is_mirror = ?", true). | ||
Find(&repos) | ||
} | ||
|
||
// IterateRepository iterate repositories | ||
func IterateRepository(f func(repo *Repository) error) error { | ||
var start int | ||
batchSize := setting.Database.IterateBufferSize | ||
for { | ||
repos := make([]*Repository, 0, batchSize) | ||
if err := db.GetEngine(db.DefaultContext).Limit(batchSize, start).Find(&repos); err != nil { | ||
return err | ||
} | ||
if len(repos) == 0 { | ||
return nil | ||
} | ||
start += len(repos) | ||
|
||
for _, repo := range repos { | ||
if err := f(repo); err != nil { | ||
return err | ||
} | ||
} | ||
} | ||
} | ||
|
||
// FindReposMapByIDs find repos as map | ||
func FindReposMapByIDs(repoIDs []int64, res map[int64]*Repository) error { | ||
return db.GetEngine(db.DefaultContext).In("id", repoIDs).Find(&res) | ||
} |
Oops, something went wrong.