0.2.58 - Requests module

This commit is contained in:
ponzischeme89
2026-08-12 14:13:19 +12:00
parent 64f19aeef2
commit 613f203cf9
27 changed files with 3026 additions and 23 deletions
+46
View File
@@ -180,6 +180,52 @@ func (s *Store) LibraryContainsProviderIDs(
return found, rows.Err()
}
// LibraryProviderItemIDs is LibraryContainsProviderIDs with the answer the request page
// needs: not only whether Emby has the title, but which item it is.
//
// That id is what lets a request that has finally downloaded stop being a status card and
// become something a viewer can press. Ordering by item_id keeps the answer stable when a
// household holds the same title twice — a duplicate import, or a remake sharing an id in
// bad metadata — so a card does not point at a different copy between two reads.
func (s *Store) LibraryProviderItemIDs(
ctx context.Context, provider string, ids []int,
) (map[int]string, error) {
found := map[int]string{}
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))
}
}
if len(values) == 0 {
return found, nil
}
rows, err := s.pool.Query(ctx, `
SELECT DISTINCT ON ((payload->'ProviderIds'->>$1)::int)
(payload->'ProviderIds'->>$1)::int, id
FROM library_items
WHERE payload->'ProviderIds'->>$1 = ANY($2::text[])
ORDER BY (payload->'ProviderIds'->>$1)::int, id`, provider, values)
if err != nil {
return nil, fmt.Errorf("store: library provider item ids: %w", err)
}
defer rows.Close()
for rows.Next() {
var (
id int
itemID string
)
if err := rows.Scan(&id, &itemID); err != nil {
return nil, err
}
found[id] = itemID
}
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.