MCPcopy
hub / github.com/syncthing/syncthing / computeProgressUpdates

Method computeProgressUpdates

lib/model/progressemitter.go:132–210  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

130}
131
132func (t *ProgressEmitter) computeProgressUpdates() []progressUpdate {
133 var progressUpdates []progressUpdate
134 for id, conn := range t.connections {
135 for _, folder := range t.foldersByConns[id] {
136 pullers, ok := t.registry[folder]
137 if !ok {
138 // There's never been any puller registered for this folder yet
139 continue
140 }
141
142 state, ok := t.sentDownloadStates[id]
143 if !ok {
144 state = &sentDownloadState{
145 folderStates: make(map[string]*sentFolderDownloadState),
146 }
147 t.sentDownloadStates[id] = state
148 }
149
150 activePullers := make([]*sharedPullerState, 0, len(pullers))
151 for _, puller := range pullers {
152 if puller.folder != folder || puller.file.IsSymlink() || puller.file.IsDirectory() || len(puller.file.Blocks) <= t.minBlocks {
153 continue
154 }
155 activePullers = append(activePullers, puller)
156 }
157
158 // For every new puller that hasn't yet been seen, it will send all the blocks the puller has available
159 // For every existing puller, it will check for new blocks, and send update for the new blocks only
160 // For every puller that we've seen before but is no longer there, we will send a forget message
161 updates := state.update(folder, activePullers)
162
163 if len(updates) > 0 {
164 progressUpdates = append(progressUpdates, progressUpdate{
165 conn: conn,
166 folder: folder,
167 updates: updates,
168 })
169 }
170 }
171 }
172
173 // Clean up sentDownloadStates for devices which we are no longer connected to.
174 for id := range t.sentDownloadStates {
175 _, ok := t.connections[id]
176 if !ok {
177 // Null out outstanding entries for device
178 delete(t.sentDownloadStates, id)
179 }
180 }
181
182 // If a folder was unshared from some device, tell it that all temp files
183 // are now gone.
184 for id, state := range t.sentDownloadStates {
185 // For each of the folders that the state is aware of,
186 // try to match it with a shared folder we've discovered above,
187 nextFolder:
188 for _, folder := range state.folders() {
189 for _, existingFolder := range t.foldersByConns[id] {

Callers 2

ServeMethod · 0.95
sendMsgsFunction · 0.80

Calls 5

foldersMethod · 0.80
cleanupMethod · 0.80
IsSymlinkMethod · 0.65
IsDirectoryMethod · 0.45
updateMethod · 0.45

Tested by 1

sendMsgsFunction · 0.64