lib/model: Return index from deviceActivity.leastBusy

This way, we don't need a second loop over the Availabilities to remove
the selected item.
This commit is contained in:
greatroar
2021-11-26 12:07:43 +01:00
committed by Jakob Borg
parent b84ee4d240
commit 6a9716e8a1
3 changed files with 26 additions and 35 deletions
+5 -13
View File
@@ -1532,8 +1532,8 @@ loop:
// Select the least busy device to pull the block from. If we found no
// feasible device at all, fail the block (and in the long run, the
// file).
selected, found := activity.leastBusy(candidates)
if !found {
found := activity.leastBusy(candidates)
if found == -1 {
if lastError != nil {
state.fail(errors.Wrap(lastError, "pull"))
} else {
@@ -1542,7 +1542,9 @@ loop:
break
}
candidates = removeAvailability(candidates, selected)
selected := candidates[found]
candidates[found] = candidates[len(candidates)-1]
candidates = candidates[:len(candidates)-1]
// Fetch the block, while marking the selected device as in use so that
// leastBusy can select another device when someone else asks.
@@ -1804,16 +1806,6 @@ func (f *sendReceiveFolder) inConflict(current, replacement protocol.Vector) boo
return false
}
func removeAvailability(availabilities []Availability, availability Availability) []Availability {
for i := range availabilities {
if availabilities[i] == availability {
availabilities[i] = availabilities[len(availabilities)-1]
return availabilities[:len(availabilities)-1]
}
}
return availabilities
}
func (f *sendReceiveFolder) moveForConflict(name, lastModBy string, scanChan chan<- string) error {
if isConflict(name) {
l.Infoln("Conflict for", name, "which is already a conflict copy; not copying again.")