Optimize GetArtists: parallel artist processing, batch album upserts, batch download lookups, retry on metadata calls
This commit is contained in:
@@ -153,6 +153,31 @@ func (r *DownloadRepository) GetByID(ctx context.Context, id string) (*Download,
|
||||
return d, nil
|
||||
}
|
||||
|
||||
func (r *DownloadRepository) GetLatestByAlbumIDs(ctx context.Context, albumIDs []string) (map[string]*Download, error) {
|
||||
if len(albumIDs) == 0 {
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
rows, err := r.pool.Query(ctx,
|
||||
`SELECT DISTINCT ON (album_id) id, torrent_id, album_id, format, quality, state, qbit_hash, save_path, error_message, queued_at, started_at, completed_at, created_at, updated_at
|
||||
FROM downloads WHERE album_id = ANY($1) ORDER BY album_id, created_at DESC`, albumIDs,
|
||||
)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("batch listing downloads: %w", err)
|
||||
}
|
||||
defer rows.Close()
|
||||
|
||||
result := make(map[string]*Download, len(albumIDs))
|
||||
for rows.Next() {
|
||||
d := &Download{}
|
||||
if err := rows.Scan(&d.ID, &d.TorrentID, &d.AlbumID, &d.Format, &d.Quality, &d.State, &d.QbitHash, &d.SavePath, &d.ErrorMessage, &d.QueuedAt, &d.StartedAt, &d.CompletedAt, &d.CreatedAt, &d.UpdatedAt); err != nil {
|
||||
return nil, fmt.Errorf("scanning download: %w", err)
|
||||
}
|
||||
result[d.AlbumID] = d
|
||||
}
|
||||
return result, nil
|
||||
}
|
||||
|
||||
func (r *DownloadRepository) HasAlbumInQuality(ctx context.Context, albumID string, format string, quality string) (bool, error) {
|
||||
var exists bool
|
||||
err := r.pool.QueryRow(ctx,
|
||||
|
||||
Reference in New Issue
Block a user