diff --git a/model/mediafile.go b/model/mediafile.go index 27e91797..9eed36eb 100644 --- a/model/mediafile.go +++ b/model/mediafile.go @@ -66,11 +66,13 @@ type MediaFileRepository interface { Put(m *MediaFile) error Get(id string) (*MediaFile, error) GetAll(options ...QueryOptions) (MediaFiles, error) + Search(q string, offset int, size int) (MediaFiles, error) + Delete(id string) error + + // Queries by path to support the scanner, no Annotations or Bookmarks required in the response FindAllByPath(path string) (MediaFiles, error) FindByPath(path string) (*MediaFile, error) FindPathsRecursively(basePath string) ([]string, error) - Search(q string, offset int, size int) (MediaFiles, error) - Delete(id string) error DeleteByPath(path string) (int64, error) AnnotatedRepository diff --git a/persistence/mediafile_repository.go b/persistence/mediafile_repository.go index 2886dd7e..a044a3d5 100644 --- a/persistence/mediafile_repository.go +++ b/persistence/mediafile_repository.go @@ -100,7 +100,7 @@ func (r *mediaFileRepository) GetAll(options ...model.QueryOptions) (model.Media } func (r *mediaFileRepository) FindByPath(path string) (*model.MediaFile, error) { - sel := r.selectMediaFile().Where(Eq{"path": path}) + sel := r.newSelect().Columns("*").Where(Eq{"path": path}) var res model.MediaFiles if err := r.queryAll(sel, &res); err != nil { return nil, err @@ -129,7 +129,7 @@ func (r *mediaFileRepository) FindAllByPath(path string) (model.MediaFiles, erro // Query by path based on https://stackoverflow.com/a/13911906/653632 path = cleanPath(path) pathLen := utf8.RuneCountInString(path) - sel0 := r.selectMediaFile().Columns(fmt.Sprintf("substr(path, %d) AS item", pathLen+2)). + sel0 := r.newSelect().Columns("media_file.*", fmt.Sprintf("substr(path, %d) AS item", pathLen+2)). Where(pathStartsWith(path)) sel := r.newSelect().Columns("*", "item NOT GLOB '*"+string(os.PathSeparator)+"*' AS isLast"). Where(Eq{"isLast": 1}).FromSelect(sel0, "sel0")