1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
|
// miscellaneous utility functions used for arches
package arches
import (
"soko/pkg/database"
"soko/pkg/models"
)
// getStabilizedVersionsForArch returns the given number of recently
// stabilized versions of a specific arch
func getStabilizedVersionsForArch(arch string, n int) ([]*models.Version, error) {
var updates []models.KeywordChange
err := database.DBCon.Model(&updates).
Relation("Version").
Relation("Commit").
Order("commit.preceding_commits DESC").
Where("stabilized::jsonb @> ?", "\""+arch+"\"").
Where("version.id IS NOT NULL").
Limit(n).
Select()
if err != nil {
return nil, err
}
stabilizedVersions := make([]*models.Version, len(updates))
for i, update := range updates {
update.Version.Commits = []*models.Commit{update.Commit}
stabilizedVersions[i] = update.Version
}
return stabilizedVersions, err
}
// getKeywordedVersionsForArch returns the given number of recently
// keyworded versions of a specific arch
func getKeywordedVersionsForArch(arch string, n int) ([]*models.Version, error) {
var updates []models.KeywordChange
err := database.DBCon.Model(&updates).
Relation("Version").
Relation("Commit").
Order("commit.preceding_commits DESC").
Where("added::jsonb @> ?", "\""+arch+"\"").
Where("version.id IS NOT NULL").
Limit(n).
Select()
if err != nil {
return nil, err
}
keywordedVersions := make([]*models.Version, len(updates))
for i, update := range updates {
update.Version.Commits = []*models.Commit{update.Commit}
keywordedVersions[i] = update.Version
}
return keywordedVersions, err
}
func getLeafPackagesForArch(arch string) ([]string, error) {
var atoms []string
atomsWithReverse := database.DBCon.Model((*models.ReverseDependency)(nil)).
Join("JOIN versions").JoinOn("reverse_dependency.reverse_dependency_atom = versions.atom").
Where("keywords LIKE ?", "%"+arch+"%").
ColumnExpr("DISTINCT reverse_dependency.atom")
err := database.DBCon.Model((*models.Version)(nil)).
Where("keywords LIKE ?", "%"+arch+"%").
Where("atom NOT IN (?)", atomsWithReverse).
Order("atom").
ColumnExpr("DISTINCT atom").
Select(&atoms)
return atoms, err
}
|