mirror of
https://codeberg.org/forgejo/forgejo.git
synced 2025-06-17 11:59:30 +00:00
Small refactor to reduce unnecessary database queries and remove duplicated functions (#33779)
(cherry picked from commit 6c8fb8d455cfe25d5aa966674624bce99fba1735)
This commit is contained in:
parent
49694242d4
commit
0a52be2a04
6 changed files with 22 additions and 7 deletions
|
@ -303,6 +303,9 @@ func GetLabelByID(ctx context.Context, labelID int64) (*Label, error) {
|
|||
// GetLabelsByIDs returns a list of labels by IDs
|
||||
func GetLabelsByIDs(ctx context.Context, labelIDs []int64, cols ...string) ([]*Label, error) {
|
||||
labels := make([]*Label, 0, len(labelIDs))
|
||||
if len(labelIDs) == 0 {
|
||||
return labels, nil
|
||||
}
|
||||
return labels, db.GetEngine(ctx).Table("label").
|
||||
In("id", labelIDs).
|
||||
Asc("name").
|
||||
|
@ -379,6 +382,9 @@ func BuildLabelNamesIssueIDsCondition(labelNames []string) *builder.Builder {
|
|||
// it silently ignores label IDs that do not belong to the repository.
|
||||
func GetLabelsInRepoByIDs(ctx context.Context, repoID int64, labelIDs []int64) ([]*Label, error) {
|
||||
labels := make([]*Label, 0, len(labelIDs))
|
||||
if len(labelIDs) == 0 {
|
||||
return labels, nil
|
||||
}
|
||||
return labels, db.GetEngine(ctx).
|
||||
Where("repo_id = ?", repoID).
|
||||
In("id", labelIDs).
|
||||
|
@ -451,6 +457,9 @@ func GetLabelInOrgByID(ctx context.Context, orgID, labelID int64) (*Label, error
|
|||
// it silently ignores label IDs that do not belong to the organization.
|
||||
func GetLabelsInOrgByIDs(ctx context.Context, orgID int64, labelIDs []int64) ([]*Label, error) {
|
||||
labels := make([]*Label, 0, len(labelIDs))
|
||||
if len(labelIDs) == 0 {
|
||||
return labels, nil
|
||||
}
|
||||
return labels, db.GetEngine(ctx).
|
||||
Where("org_id = ?", orgID).
|
||||
In("id", labelIDs).
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue