0.2.54
This commit is contained in:
@@ -146,6 +146,40 @@ func (s *Store) SearchLibrary(ctx context.Context, term string, limit int) ([]js
|
||||
return collectPayloads(rows)
|
||||
}
|
||||
|
||||
// LibraryContainsProviderIDs reports which external catalogue ids are already represented in
|
||||
// Emby. ProviderIds stays inside the imported payload because it is not a ranking field;
|
||||
// request autocomplete is the one place that needs to compare it with Radarr/Sonarr.
|
||||
func (s *Store) LibraryContainsProviderIDs(
|
||||
ctx context.Context, provider string, ids []int,
|
||||
) (map[int]bool, error) {
|
||||
found := map[int]bool{}
|
||||
if len(ids) == 0 {
|
||||
return found, nil
|
||||
}
|
||||
values := make([]string, 0, len(ids))
|
||||
for _, id := range ids {
|
||||
if id > 0 {
|
||||
values = append(values, fmt.Sprint(id))
|
||||
}
|
||||
}
|
||||
rows, err := s.pool.Query(ctx, `
|
||||
SELECT DISTINCT (payload->'ProviderIds'->>$1)::int
|
||||
FROM library_items
|
||||
WHERE payload->'ProviderIds'->>$1 = ANY($2::text[])`, provider, values)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("store: library provider ids: %w", err)
|
||||
}
|
||||
defer rows.Close()
|
||||
for rows.Next() {
|
||||
var id int
|
||||
if err := rows.Scan(&id); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
found[id] = true
|
||||
}
|
||||
return found, rows.Err()
|
||||
}
|
||||
|
||||
// LibraryCandidates returns unwatched-agnostic candidates in the given genres, for the
|
||||
// recommendation engine. User state is applied by the caller, which is the only place
|
||||
// that knows it.
|
||||
|
||||
Reference in New Issue
Block a user