mirror of
https://github.com/navidrome/navidrome.git
synced 2026-08-01 07:21:17 +00:00
fix: parallelize batch rate API requests and guard selectedIds
- Use Promise.all instead of sequential for...of loop - Add defensive check for empty/undefined selectedIds - Merge rating and clear-rating logic into single loop Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
parent
6a4be58c8c
commit
46bc45e939
@ -95,24 +95,25 @@ export const BatchRateButton = ({
|
||||
|
||||
const handleApply = async () => {
|
||||
setOpen(false)
|
||||
if (!selectedIds || selectedIds.length === 0) {
|
||||
unselectAll(resource)
|
||||
return
|
||||
}
|
||||
try {
|
||||
for (const id of selectedIds) {
|
||||
const requests = []
|
||||
selectedIds.forEach((id) => {
|
||||
if (rating > 0) {
|
||||
await subsonic.setRating(id, rating)
|
||||
requests.push(subsonic.setRating(id, rating))
|
||||
} else if (rating === -1) {
|
||||
requests.push(subsonic.setRating(id, 0))
|
||||
}
|
||||
if (starred === true) {
|
||||
await subsonic.star(id)
|
||||
requests.push(subsonic.star(id))
|
||||
} else if (starred === false) {
|
||||
await subsonic.unstar(id)
|
||||
requests.push(subsonic.unstar(id))
|
||||
}
|
||||
}
|
||||
// Clear rating if "delete" was chosen (rating === -1)
|
||||
if (rating === -1) {
|
||||
for (const id of selectedIds) {
|
||||
await subsonic.setRating(id, 0)
|
||||
}
|
||||
}
|
||||
// Force React-Admin to re-fetch the records, then refresh the view
|
||||
})
|
||||
await Promise.all(requests)
|
||||
await dataProvider.getMany(resource, { ids: selectedIds })
|
||||
notify('message.batchRateSuccess', { type: 'info' })
|
||||
refresh()
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user