lib/db: Constant/unused args and return values, double it.Release (#8259)

This commit is contained in:
greatroar 2022-04-27 20:32:44 +02:00 committed by GitHub
parent 49488c0e71
commit d00a30069a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 14 additions and 22 deletions

View File

@ -841,6 +841,7 @@ func rewriteGlobals(t readWriteTransaction) error {
return err return err
} }
defer it.Release() defer it.Release()
for it.Next() { for it.Next() {
var vl VersionListDeprecated var vl VersionListDeprecated
if err := vl.Unmarshal(it.Value()); err != nil { if err := vl.Unmarshal(it.Value()); err != nil {
@ -858,10 +859,7 @@ func rewriteGlobals(t readWriteTransaction) error {
} }
} }
newVl, err := convertVersionList(vl) newVl := convertVersionList(vl)
if err != nil {
return err
}
if err := t.Put(it.Key(), mustMarshal(&newVl)); err != nil { if err := t.Put(it.Key(), mustMarshal(&newVl)); err != nil {
return err return err
} }
@ -869,11 +867,10 @@ func rewriteGlobals(t readWriteTransaction) error {
return err return err
} }
} }
it.Release()
return it.Error() return it.Error()
} }
func convertVersionList(vl VersionListDeprecated) (VersionList, error) { func convertVersionList(vl VersionListDeprecated) VersionList {
var newVl VersionList var newVl VersionList
var newPos, oldPos int var newPos, oldPos int
var lastVersion protocol.Vector var lastVersion protocol.Vector
@ -893,7 +890,7 @@ func convertVersionList(vl VersionListDeprecated) (VersionList, error) {
} }
if oldPos == len(vl.Versions) { if oldPos == len(vl.Versions) {
return newVl, nil return newVl
} }
if len(newVl.RawVersions) == 0 { if len(newVl.RawVersions) == 0 {
@ -923,7 +920,7 @@ outer:
newPos++ newPos++
} }
return newVl, nil return newVl
} }
func getGlobalVersionsByKeyBefore11(key []byte, t readOnlyTransaction) (VersionListDeprecated, error) { func getGlobalVersionsByKeyBefore11(key []byte, t readOnlyTransaction) (VersionListDeprecated, error) {

View File

@ -262,11 +262,9 @@ func (vl *VersionList) update(folder, device []byte, file protocol.FileIntf, t r
oldFV = oldFV.copy() oldFV = oldFV.copy()
// Remove ourselves first // Remove ourselves first
removedFV, haveRemoved, _, err := vl.pop(device, []byte(file.FileName())) removedFV, haveRemoved, _ := vl.pop(device)
if err == nil { // Find position and insert the file
// Find position and insert the file err := vl.insert(folder, device, file, t)
err = vl.insert(folder, device, file, t)
}
if err != nil { if err != nil {
return FileVersion{}, FileVersion{}, FileVersion{}, false, false, false, err return FileVersion{}, FileVersion{}, FileVersion{}, false, false, false, err
} }
@ -315,28 +313,28 @@ func (vl *VersionList) insertAt(i int, v FileVersion) {
// pop removes the given device from the VersionList and returns the FileVersion // pop removes the given device from the VersionList and returns the FileVersion
// before removing the device, whether it was found/removed at all and whether // before removing the device, whether it was found/removed at all and whether
// the global changed in the process. // the global changed in the process.
func (vl *VersionList) pop(device, name []byte) (FileVersion, bool, bool, error) { func (vl *VersionList) pop(device []byte) (FileVersion, bool, bool) {
invDevice, i, j, ok := vl.findDevice(device) invDevice, i, j, ok := vl.findDevice(device)
if !ok { if !ok {
return FileVersion{}, false, false, nil return FileVersion{}, false, false
} }
globalPos := vl.findGlobal() globalPos := vl.findGlobal()
if vl.RawVersions[i].deviceCount() == 1 { if vl.RawVersions[i].deviceCount() == 1 {
fv := vl.RawVersions[i] fv := vl.RawVersions[i]
vl.popVersionAt(i) vl.popVersionAt(i)
return fv, true, globalPos == i, nil return fv, true, globalPos == i
} }
oldFV := vl.RawVersions[i].copy() oldFV := vl.RawVersions[i].copy()
if invDevice { if invDevice {
vl.RawVersions[i].InvalidDevices = popDeviceAt(vl.RawVersions[i].InvalidDevices, j) vl.RawVersions[i].InvalidDevices = popDeviceAt(vl.RawVersions[i].InvalidDevices, j)
return oldFV, true, false, nil return oldFV, true, false
} }
vl.RawVersions[i].Devices = popDeviceAt(vl.RawVersions[i].Devices, j) vl.RawVersions[i].Devices = popDeviceAt(vl.RawVersions[i].Devices, j)
// If the last valid device of the previous global was removed above, // If the last valid device of the previous global was removed above,
// the global changed. // the global changed.
return oldFV, true, len(vl.RawVersions[i].Devices) == 0 && globalPos == i, nil return oldFV, true, len(vl.RawVersions[i].Devices) == 0 && globalPos == i
} }
// Get returns a FileVersion that contains the given device and whether it has // Get returns a FileVersion that contains the given device and whether it has

View File

@ -825,10 +825,7 @@ func (t readWriteTransaction) removeFromGlobal(gk, keyBuf, folder, device, file
return keyBuf, t.Delete(gk) return keyBuf, t.Delete(gk)
} }
removedFV, haveRemoved, globalChanged, err := fl.pop(device, file) removedFV, haveRemoved, globalChanged := fl.pop(device)
if err != nil {
return nil, err
}
if !haveRemoved { if !haveRemoved {
// There is no version for the given device // There is no version for the given device
return keyBuf, nil return keyBuf, nil