MCPcopy Index your code
hub / github.com/dnote/dnote / getSyncFragments

Function getSyncFragments

pkg/cli/cmd/sync/sync.go:164–189  ·  view source on GitHub ↗

getSyncFragments repeatedly gets all sync fragments after the specified usn until there is no more new data remaining and returns the buffered list

(ctx context.DnoteCtx, afterUSN int)

Source from the content-addressed store, hash-verified

162// getSyncFragments repeatedly gets all sync fragments after the specified usn until there is no more new data
163// remaining and returns the buffered list
164func getSyncFragments(ctx context.DnoteCtx, afterUSN int) ([]client.SyncFragment, error) {
165 var buf []client.SyncFragment
166
167 nextAfterUSN := afterUSN
168
169 for {
170 resp, err := client.GetSyncFragment(ctx, nextAfterUSN)
171 if err != nil {
172 return buf, errors.Wrap(err, "getting sync fragment")
173 }
174
175 frag := resp.Fragment
176 buf = append(buf, frag)
177
178 nextAfterUSN = frag.FragMaxUSN
179
180 // if there is no more data, break
181 if nextAfterUSN == 0 {
182 break
183 }
184 }
185
186 log.Debug("received sync fragments: %+v\n", redactSyncFragments(buf))
187
188 return buf, nil
189}
190
191// redactSyncFragments returns a deep copy of sync fragments with sensitive fields (note body, book label) removed for safe logging
192func redactSyncFragments(fragments []client.SyncFragment) []client.SyncFragment {

Callers 1

getSyncListFunction · 0.85

Calls 3

GetSyncFragmentFunction · 0.92
DebugFunction · 0.92
redactSyncFragmentsFunction · 0.85

Tested by

no test coverage detected