IterateContents invokes the provided callback for each content starting with a specified prefix and possibly including deleted items.
(ctx context.Context, opts IterateOptions, callback IterateCallback)
| 107 | // IterateContents invokes the provided callback for each content starting with a specified prefix |
| 108 | // and possibly including deleted items. |
| 109 | func (bm *WriteManager) IterateContents(ctx context.Context, opts IterateOptions, callback IterateCallback) error { |
| 110 | if opts.Range == (IDRange{}) { |
| 111 | // range not specified - default to AllIDs |
| 112 | opts.Range = index.AllIDs |
| 113 | } |
| 114 | |
| 115 | callback, cleanup := maybeParallelExecutor(opts.Parallel, callback) |
| 116 | defer cleanup() //nolint:errcheck |
| 117 | |
| 118 | uncommitted := bm.snapshotUncommittedItems(ctx) |
| 119 | |
| 120 | invokeCallback := func(i Info) error { |
| 121 | if !opts.IncludeDeleted { |
| 122 | if ci, ok := uncommitted[i.ContentID]; ok { |
| 123 | if ci.Deleted { |
| 124 | return nil |
| 125 | } |
| 126 | } else if i.Deleted { |
| 127 | return nil |
| 128 | } |
| 129 | } |
| 130 | |
| 131 | if !opts.Range.Contains(i.ContentID) { |
| 132 | return nil |
| 133 | } |
| 134 | |
| 135 | return callback(i) |
| 136 | } |
| 137 | |
| 138 | if len(uncommitted) == 0 && opts.IncludeDeleted && opts.Range == index.AllIDs && opts.Parallel <= 1 { |
| 139 | // fast path, invoke callback directly |
| 140 | invokeCallback = callback |
| 141 | } |
| 142 | |
| 143 | for _, bi := range uncommitted { |
| 144 | _ = invokeCallback(bi) |
| 145 | } |
| 146 | |
| 147 | if err := bm.maybeRefreshIndexes(ctx); err != nil { |
| 148 | return err |
| 149 | } |
| 150 | |
| 151 | if err := bm.committedContents.listContents(opts.Range, invokeCallback); err != nil { |
| 152 | return err |
| 153 | } |
| 154 | |
| 155 | return cleanup() |
| 156 | } |
| 157 | |
| 158 | // IteratePackOptions are the options used to iterate over packs. |
| 159 | type IteratePackOptions struct { |
no test coverage detected