Prune removes all state instances that are not in use by a variable.
(ctx context.Context)
| 156 | |
| 157 | // Prune removes all state instances that are not in use by a variable. |
| 158 | func (s *ShellStateStore) Prune(ctx context.Context) int { |
| 159 | hctx := HandlerCtx(ctx) |
| 160 | if hctx == nil { |
| 161 | return 0 |
| 162 | } |
| 163 | |
| 164 | used := make(map[string]struct{}) |
| 165 | |
| 166 | hctx.Env.Each(func(_ string, v expand.Variable) bool { |
| 167 | for key := range FindStateKeys(v.String()) { |
| 168 | used[key] = struct{}{} |
| 169 | } |
| 170 | return true |
| 171 | }) |
| 172 | |
| 173 | count := 0 |
| 174 | s.mu.Lock() |
| 175 | for key := range s.data { |
| 176 | if _, exists := used[key]; !exists { |
| 177 | delete(s.data, key) |
| 178 | count++ |
| 179 | } |
| 180 | } |
| 181 | s.mu.Unlock() |
| 182 | return count |
| 183 | } |
| 184 | |
| 185 | func (s *ShellStateStore) debug(ctx context.Context, dump bool) { |
| 186 | slog := slog.SpanLogger(ctx, InstrumentationLibrary) |
nothing calls this directly
no test coverage detected