Speed up Global() at the price of Update() in fileset
This commit is contained in:
parent
48bfc2d9ed
commit
9d535b13cf
37
files/set.go
37
files/set.go
|
@ -11,8 +11,9 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
type fileRecord struct {
|
type fileRecord struct {
|
||||||
Usage int
|
File scanner.File
|
||||||
File scanner.File
|
Usage int
|
||||||
|
Global bool
|
||||||
}
|
}
|
||||||
|
|
||||||
type bitset uint64
|
type bitset uint64
|
||||||
|
@ -110,13 +111,17 @@ func (m *Set) Need(id uint) []scanner.File {
|
||||||
var fs = make([]scanner.File, 0, len(m.globalKey)/2) // Just a guess, but avoids too many reallocations
|
var fs = make([]scanner.File, 0, len(m.globalKey)/2) // Just a guess, but avoids too many reallocations
|
||||||
m.Lock()
|
m.Lock()
|
||||||
rkID := m.remoteKey[id]
|
rkID := m.remoteKey[id]
|
||||||
for name, gk := range m.globalKey {
|
for gk, gf := range m.files {
|
||||||
if gk.newerThan(rkID[name]) {
|
if !gf.Global {
|
||||||
file := m.files[gk].File
|
continue
|
||||||
if file.Flags&protocol.FlagDirectory == 0 || // Regular file
|
}
|
||||||
file.Flags&(protocol.FlagDirectory|protocol.FlagDeleted) == protocol.FlagDirectory { // Non-deleted directory
|
|
||||||
fs = append(fs, file)
|
file := gf.File
|
||||||
}
|
switch {
|
||||||
|
case file.Flags&protocol.FlagDirectory == 0 && gk.newerThan(rkID[gk.Name]):
|
||||||
|
fs = append(fs, file)
|
||||||
|
case file.Flags&(protocol.FlagDirectory|protocol.FlagDeleted) == protocol.FlagDirectory && gk.newerThan(rkID[gk.Name]):
|
||||||
|
fs = append(fs, file)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
m.Unlock()
|
m.Unlock()
|
||||||
|
@ -142,8 +147,10 @@ func (m *Set) Global() []scanner.File {
|
||||||
}
|
}
|
||||||
var fs = make([]scanner.File, 0, len(m.globalKey))
|
var fs = make([]scanner.File, 0, len(m.globalKey))
|
||||||
m.Lock()
|
m.Lock()
|
||||||
for _, rk := range m.globalKey {
|
for _, file := range m.files {
|
||||||
fs = append(fs, m.files[rk].File)
|
if file.Global {
|
||||||
|
fs = append(fs, file.File)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
m.Unlock()
|
m.Unlock()
|
||||||
return fs
|
return fs
|
||||||
|
@ -237,6 +244,14 @@ func (m *Set) update(cid uint, fs []scanner.File) {
|
||||||
av |= 1 << cid
|
av |= 1 << cid
|
||||||
m.globalAvailability[n] = av
|
m.globalAvailability[n] = av
|
||||||
case fk.newerThan(gk):
|
case fk.newerThan(gk):
|
||||||
|
if ok {
|
||||||
|
f := m.files[gk]
|
||||||
|
f.Global = false
|
||||||
|
m.files[gk] = f
|
||||||
|
}
|
||||||
|
f := m.files[fk]
|
||||||
|
f.Global = true
|
||||||
|
m.files[fk] = f
|
||||||
m.globalKey[n] = fk
|
m.globalKey[n] = fk
|
||||||
m.globalAvailability[n] = 1 << cid
|
m.globalAvailability[n] = 1 << cid
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue