api tests hash passwords at bcrypt's lowest cost; one genre splitter (#8330, #8331)
release / web (push) Successful in 1m30s
release / go (push) Successful in 1m55s
release / govulncheck (push) Successful in 19s
release / integration (push) Successful in 2m43s
release / android (push) Successful in 4m31s
release / Build signed APK (push) Successful in 5m0s
release / Attach APK to the Release (tag releases only) (push) Skipped
release / Publish the release image to GHCR (dispatch only) (push) Skipped
release / Build + push container image (push) Successful in 13s
release / Verify release artifacts (tag releases only) (push) Skipped
release / web (push) Successful in 1m30s
release / go (push) Successful in 1m55s
release / govulncheck (push) Successful in 19s
release / integration (push) Successful in 2m43s
release / android (push) Successful in 4m31s
release / Build signed APK (push) Successful in 5m0s
release / Attach APK to the Release (tag releases only) (push) Skipped
release / Publish the release image to GHCR (dispatch only) (push) Skipped
release / Build + push container image (push) Successful in 13s
release / Verify release artifacts (tag releases only) (push) Skipped
#8330: every password the api handlers store goes through hashPassword at bcrypt.DefaultCost, most of a second per hash under -race, so the password tests took about 1.4s each, roughly 15s of the package. The cost is now a package variable the tests' TestMain lowers to MinCost, after refusing a production default below bcrypt.DefaultCost. #8331: recommendation and taste each had a splitGenres and subsonic's hasGenre split inline, the same rule three times. internal/genretag.Split is the one copy, a stdlib-only leaf, and the two TestSplitGenres tables are one. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -10,12 +10,12 @@ import (
|
||||
"fmt"
|
||||
"log/slog"
|
||||
"sort"
|
||||
"strings"
|
||||
|
||||
"github.com/jackc/pgx/v5/pgtype"
|
||||
"github.com/jackc/pgx/v5/pgxpool"
|
||||
|
||||
"github.com/Fabled-Sword/minstrel/internal/db/dbq"
|
||||
"github.com/Fabled-Sword/minstrel/internal/genretag"
|
||||
"github.com/Fabled-Sword/minstrel/internal/mood"
|
||||
)
|
||||
|
||||
@@ -185,7 +185,7 @@ func accumulate(
|
||||
for _, p := range plays {
|
||||
e := Engagement(p.Completion, cfg.Engagement) * decay(p.AgeDays, cfg.HalfLifeDays)
|
||||
artistW[p.ArtistID] += e
|
||||
for _, tag := range splitGenres(p.Genre) {
|
||||
for _, tag := range genretag.Split(p.Genre) {
|
||||
tagW[tag] += e
|
||||
}
|
||||
foldEnrichedTags(tagW, playedTags[p.TrackID], e, cfg.EnrichedTagScale)
|
||||
@@ -204,7 +204,7 @@ func accumulate(
|
||||
likedTags := groupTagsByTrack(likedTagRows)
|
||||
for _, lt := range likedTracks {
|
||||
artistW[lt.ArtistID] += cfg.TrackLikeBonus
|
||||
for _, tag := range splitGenres(lt.Genre) {
|
||||
for _, tag := range genretag.Split(lt.Genre) {
|
||||
tagW[tag] += cfg.TagLikeBonus
|
||||
}
|
||||
foldEnrichedTags(tagW, likedTags[lt.TrackID], cfg.TagLikeBonus, cfg.EnrichedTagScale)
|
||||
@@ -400,22 +400,3 @@ func uuidString(u pgtype.UUID) string {
|
||||
return fmt.Sprintf("%x-%x-%x-%x-%x",
|
||||
u.Bytes[0:4], u.Bytes[4:6], u.Bytes[6:8], u.Bytes[8:10], u.Bytes[10:16])
|
||||
}
|
||||
|
||||
// splitGenres splits a track's denormalized genre string on the common
|
||||
// multi-genre delimiters, trimming whitespace and dropping empties. Mirrors
|
||||
// the recommendation package's splitter (kept local to avoid a dependency).
|
||||
func splitGenres(genre *string) []string {
|
||||
if genre == nil || *genre == "" {
|
||||
return nil
|
||||
}
|
||||
parts := strings.FieldsFunc(*genre, func(r rune) bool {
|
||||
return r == ';' || r == ','
|
||||
})
|
||||
out := make([]string, 0, len(parts))
|
||||
for _, p := range parts {
|
||||
if p = strings.TrimSpace(p); p != "" {
|
||||
out = append(out, p)
|
||||
}
|
||||
}
|
||||
return out
|
||||
}
|
||||
|
||||
@@ -88,32 +88,6 @@ func TestApplyFloor_ClampsNegatives(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestSplitGenres(t *testing.T) {
|
||||
mk := func(s string) *string { return &s }
|
||||
cases := []struct {
|
||||
in *string
|
||||
want []string
|
||||
}{
|
||||
{nil, nil},
|
||||
{mk(""), nil},
|
||||
{mk("Rock"), []string{"Rock"}},
|
||||
{mk(" Rock "), []string{"Rock"}},
|
||||
{mk("Rock; Pop, Jazz"), []string{"Rock", "Pop", "Jazz"}},
|
||||
}
|
||||
for _, c := range cases {
|
||||
got := splitGenres(c.in)
|
||||
if len(got) != len(c.want) {
|
||||
t.Errorf("splitGenres(%v) len = %d, want %d", c.in, len(got), len(c.want))
|
||||
continue
|
||||
}
|
||||
for i := range got {
|
||||
if got[i] != c.want[i] {
|
||||
t.Errorf("splitGenres(%v)[%d] = %q, want %q", c.in, i, got[i], c.want[i])
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestUuidLess_Orders(t *testing.T) {
|
||||
a := pgtype.UUID{Bytes: [16]byte{1}, Valid: true}
|
||||
b := pgtype.UUID{Bytes: [16]byte{2}, Valid: true}
|
||||
|
||||
Reference in New Issue
Block a user