@ -287,9 +287,10 @@ func (opts *PackageSearchOptions) configureOrderBy(e db.Engine) {
// SearchVersions gets all versions of packages matching the search options
// SearchVersions gets all versions of packages matching the search options
func SearchVersions ( ctx context . Context , opts * PackageSearchOptions ) ( [ ] * PackageVersion , int64 , error ) {
func SearchVersions ( ctx context . Context , opts * PackageSearchOptions ) ( [ ] * PackageVersion , int64 , error ) {
sess := db . GetEngine ( ctx ) .
sess := db . GetEngine ( ctx ) .
Where ( opts . ToConds ( ) ) .
Select ( "package_version.*" ) .
Table ( "package_version" ) .
Table ( "package_version" ) .
Join ( "INNER" , "package" , "package.id = package_version.package_id" )
Join ( "INNER" , "package" , "package.id = package_version.package_id" ) .
Where ( opts . ToConds ( ) )
opts . configureOrderBy ( sess )
opts . configureOrderBy ( sess )
@ -304,19 +305,18 @@ func SearchVersions(ctx context.Context, opts *PackageSearchOptions) ([]*Package
// SearchLatestVersions gets the latest version of every package matching the search options
// SearchLatestVersions gets the latest version of every package matching the search options
func SearchLatestVersions ( ctx context . Context , opts * PackageSearchOptions ) ( [ ] * PackageVersion , int64 , error ) {
func SearchLatestVersions ( ctx context . Context , opts * PackageSearchOptions ) ( [ ] * PackageVersion , int64 , error ) {
cond := opts . ToConds ( ) .
in := builder .
And ( builder . Expr ( "pv2.id IS NULL" ) )
Select ( "MAX(package_version.id)" ) .
From ( "package_version" ) .
joinCond := builder . Expr ( "package_version.package_id = pv2.package_id AND (package_version.created_unix < pv2.created_unix OR (package_version.created_unix = pv2.created_unix AND package_version.id < pv2.id))" )
InnerJoin ( "package" , "package.id = package_version.package_id" ) .
if opts . IsInternal . Has ( ) {
Where ( opts . ToConds ( ) ) .
joinCond = joinCond . And ( builder . Eq { "pv2.is_internal" : opts . IsInternal . Value ( ) } )
GroupBy ( "package_version.package_id" )
}
sess := db . GetEngine ( ctx ) .
sess := db . GetEngine ( ctx ) .
Select ( "package_version.*" ) .
Table ( "package_version" ) .
Table ( "package_version" ) .
Join ( "LEFT" , "package_version pv2" , joinCond ) .
Join ( "INNER" , "package" , "package.id = package_version.package_id" ) .
Join ( "INNER" , "package" , "package.id = package_version.package_id" ) .
Where ( c ond)
Where ( builder . In ( "package_versi on.i d" , in ) )
opts . configureOrderBy ( sess )
opts . configureOrderBy ( sess )