mirror of
https://github.com/navidrome/navidrome.git
synced 2026-04-26 10:30:46 +00:00
Some checks are pending
Pipeline: Test, Lint, Build / Get version info (push) Waiting to run
Pipeline: Test, Lint, Build / Lint Go code (push) Waiting to run
Pipeline: Test, Lint, Build / Test Go code (push) Waiting to run
Pipeline: Test, Lint, Build / Test JS code (push) Waiting to run
Pipeline: Test, Lint, Build / Lint i18n files (push) Waiting to run
Pipeline: Test, Lint, Build / Check Docker configuration (push) Waiting to run
Pipeline: Test, Lint, Build / Build (push) Blocked by required conditions
Pipeline: Test, Lint, Build / Build-1 (push) Blocked by required conditions
Pipeline: Test, Lint, Build / Build-2 (push) Blocked by required conditions
Pipeline: Test, Lint, Build / Build-3 (push) Blocked by required conditions
Pipeline: Test, Lint, Build / Build-4 (push) Blocked by required conditions
Pipeline: Test, Lint, Build / Build-5 (push) Blocked by required conditions
Pipeline: Test, Lint, Build / Build-6 (push) Blocked by required conditions
Pipeline: Test, Lint, Build / Build-7 (push) Blocked by required conditions
Pipeline: Test, Lint, Build / Build-8 (push) Blocked by required conditions
Pipeline: Test, Lint, Build / Build-9 (push) Blocked by required conditions
Pipeline: Test, Lint, Build / Build-10 (push) Blocked by required conditions
Pipeline: Test, Lint, Build / Push to GHCR (push) Blocked by required conditions
Pipeline: Test, Lint, Build / Push to Docker Hub (push) Blocked by required conditions
Pipeline: Test, Lint, Build / Cleanup digest artifacts (push) Blocked by required conditions
Pipeline: Test, Lint, Build / Build Windows installers (push) Blocked by required conditions
Pipeline: Test, Lint, Build / Package/Release (push) Blocked by required conditions
Pipeline: Test, Lint, Build / Upload Linux PKG (push) Blocked by required conditions
* fix(subsonic): optimize search3 for high-cardinality FTS queries Use a two-phase query strategy for FTS5 searches to avoid the performance penalty of expensive LEFT JOINs (annotation, bookmark, library) on high-cardinality results like "the". Phase 1 runs a lightweight query (main table + FTS index only) to get sorted, paginated rowids. Phase 2 hydrates only those few rowids with the full JOINs, making them nearly free. For queries with complex ORDER BY expressions that reference joined tables (e.g. artist search sorted by play count), the optimization is skipped and the original single-query approach is used. * fix(search): update order by clauses to include 'rank' for FTS queries Signed-off-by: Deluan <deluan@navidrome.org> * fix(search): reintroduce 'rank' in Phase 2 ORDER BY for FTS queries Signed-off-by: Deluan <deluan@navidrome.org> * fix(search): remove 'rank' from ORDER BY in non-FTS queries and adjust two-phase query handling Signed-off-by: Deluan <deluan@navidrome.org> * fix(search): update FTS ranking to use bm25 weights and simplify ORDER BY qualification Signed-off-by: Deluan <deluan@navidrome.org> * fix(search): refine FTS query handling and improve comments for clarity Signed-off-by: Deluan <deluan@navidrome.org> * fix(search): refactor full-text search handling to streamline query strategy selection and improve LIKE fallback logic. Increase e2e coverage for search3 Signed-off-by: Deluan <deluan@navidrome.org> * refactor: enhance FTS column definitions and relevance weights Signed-off-by: Deluan <deluan@navidrome.org> * fix(search): refactor Search method signatures to remove offset and size parameters, streamline query handling Signed-off-by: Deluan <deluan@navidrome.org> * fix(search): allow single-character queries in search strategies and update related tests Signed-off-by: Deluan <deluan@navidrome.org> * fix(search): make FTS Phase 1 treat Max=0 as no limit, reorganize tests FTS Phase 1 unconditionally called Limit(uint64(options.Max)), which produced LIMIT 0 when Max was zero. This diverged from applyOptions where Max=0 means no limit. Now Phase 1 mirrors applyOptions: only add LIMIT/OFFSET when the value is positive. Also moved legacy backend integration tests from sql_search_fts_test.go to sql_search_like_test.go and added regression tests for the Max=0 behavior on both backends. * refactor: simplify callSearch function by removing variadic options and directly using QueryOptions Signed-off-by: Deluan <deluan@navidrome.org> * fix(search): implement ftsQueryDegraded function to detect significant content loss in FTS queries Signed-off-by: Deluan <deluan@navidrome.org> --------- Signed-off-by: Deluan <deluan@navidrome.org>
188 lines
4.1 KiB
Go
188 lines
4.1 KiB
Go
package tests
|
|
|
|
import (
|
|
"errors"
|
|
"time"
|
|
|
|
"github.com/navidrome/navidrome/model"
|
|
"github.com/navidrome/navidrome/model/id"
|
|
)
|
|
|
|
func CreateMockAlbumRepo() *MockAlbumRepo {
|
|
return &MockAlbumRepo{
|
|
Data: make(map[string]*model.Album),
|
|
}
|
|
}
|
|
|
|
type MockAlbumRepo struct {
|
|
model.AlbumRepository
|
|
Data map[string]*model.Album
|
|
All model.Albums
|
|
Err bool
|
|
Options model.QueryOptions
|
|
ReassignAnnotationCalls map[string]string // prevID -> newID
|
|
CopyAttributesCalls map[string]string // fromID -> toID
|
|
}
|
|
|
|
func (m *MockAlbumRepo) SetError(err bool) {
|
|
m.Err = err
|
|
}
|
|
|
|
func (m *MockAlbumRepo) SetData(albums model.Albums) {
|
|
m.Data = make(map[string]*model.Album, len(albums))
|
|
m.All = albums
|
|
for i, a := range m.All {
|
|
m.Data[a.ID] = &m.All[i]
|
|
}
|
|
}
|
|
|
|
func (m *MockAlbumRepo) Exists(id string) (bool, error) {
|
|
if m.Err {
|
|
return false, errors.New("unexpected error")
|
|
}
|
|
_, found := m.Data[id]
|
|
return found, nil
|
|
}
|
|
|
|
func (m *MockAlbumRepo) Get(id string) (*model.Album, error) {
|
|
if m.Err {
|
|
return nil, errors.New("unexpected error")
|
|
}
|
|
if d, ok := m.Data[id]; ok {
|
|
return d, nil
|
|
}
|
|
return nil, model.ErrNotFound
|
|
}
|
|
|
|
func (m *MockAlbumRepo) Put(al *model.Album) error {
|
|
if m.Err {
|
|
return errors.New("unexpected error")
|
|
}
|
|
if al.ID == "" {
|
|
al.ID = id.NewRandom()
|
|
}
|
|
m.Data[al.ID] = al
|
|
return nil
|
|
}
|
|
|
|
func (m *MockAlbumRepo) GetAll(qo ...model.QueryOptions) (model.Albums, error) {
|
|
if len(qo) > 0 {
|
|
m.Options = qo[0]
|
|
}
|
|
if m.Err {
|
|
return nil, errors.New("unexpected error")
|
|
}
|
|
return m.All, nil
|
|
}
|
|
|
|
func (m *MockAlbumRepo) IncPlayCount(id string, timestamp time.Time) error {
|
|
if m.Err {
|
|
return errors.New("unexpected error")
|
|
}
|
|
if d, ok := m.Data[id]; ok {
|
|
d.PlayCount++
|
|
d.PlayDate = ×tamp
|
|
return nil
|
|
}
|
|
return model.ErrNotFound
|
|
}
|
|
func (m *MockAlbumRepo) CountAll(...model.QueryOptions) (int64, error) {
|
|
return int64(len(m.All)), nil
|
|
}
|
|
|
|
func (m *MockAlbumRepo) GetTouchedAlbums(libID int) (model.AlbumCursor, error) {
|
|
if m.Err {
|
|
return nil, errors.New("unexpected error")
|
|
}
|
|
return func(yield func(model.Album, error) bool) {
|
|
for _, a := range m.Data {
|
|
if a.ID == "error" {
|
|
if !yield(*a, errors.New("error")) {
|
|
break
|
|
}
|
|
continue
|
|
}
|
|
if a.LibraryID != libID {
|
|
continue
|
|
}
|
|
if !yield(*a, nil) {
|
|
break
|
|
}
|
|
}
|
|
}, nil
|
|
}
|
|
|
|
func (m *MockAlbumRepo) UpdateExternalInfo(album *model.Album) error {
|
|
if m.Err {
|
|
return errors.New("unexpected error")
|
|
}
|
|
return nil
|
|
}
|
|
|
|
func (m *MockAlbumRepo) Search(q string, options ...model.QueryOptions) (model.Albums, error) {
|
|
if len(options) > 0 {
|
|
m.Options = options[0]
|
|
}
|
|
if m.Err {
|
|
return nil, errors.New("unexpected error")
|
|
}
|
|
// Simple mock implementation - just return all albums for testing
|
|
return m.All, nil
|
|
}
|
|
|
|
// ReassignAnnotation reassigns annotations from one album to another
|
|
func (m *MockAlbumRepo) ReassignAnnotation(prevID string, newID string) error {
|
|
if m.Err {
|
|
return errors.New("unexpected error")
|
|
}
|
|
// Mock implementation - track the reassignment calls
|
|
if m.ReassignAnnotationCalls == nil {
|
|
m.ReassignAnnotationCalls = make(map[string]string)
|
|
}
|
|
m.ReassignAnnotationCalls[prevID] = newID
|
|
return nil
|
|
}
|
|
|
|
// CopyAttributes copies attributes from one album to another
|
|
func (m *MockAlbumRepo) CopyAttributes(fromID, toID string, columns ...string) error {
|
|
if m.Err {
|
|
return errors.New("unexpected error")
|
|
}
|
|
from, ok := m.Data[fromID]
|
|
if !ok {
|
|
return model.ErrNotFound
|
|
}
|
|
to, ok := m.Data[toID]
|
|
if !ok {
|
|
return model.ErrNotFound
|
|
}
|
|
for _, col := range columns {
|
|
switch col {
|
|
case "created_at":
|
|
to.CreatedAt = from.CreatedAt
|
|
}
|
|
}
|
|
if m.CopyAttributesCalls == nil {
|
|
m.CopyAttributesCalls = make(map[string]string)
|
|
}
|
|
m.CopyAttributesCalls[fromID] = toID
|
|
return nil
|
|
}
|
|
|
|
// SetRating sets the rating for an album
|
|
func (m *MockAlbumRepo) SetRating(rating int, itemID string) error {
|
|
if m.Err {
|
|
return errors.New("unexpected error")
|
|
}
|
|
return nil
|
|
}
|
|
|
|
// SetStar sets the starred status for albums
|
|
func (m *MockAlbumRepo) SetStar(starred bool, itemIDs ...string) error {
|
|
if m.Err {
|
|
return errors.New("unexpected error")
|
|
}
|
|
return nil
|
|
}
|
|
|
|
var _ model.AlbumRepository = (*MockAlbumRepo)(nil)
|