processUpdate adds a metadata update to the batch with deduplication based on timestamp.
(update update)
| 238 | |
| 239 | // processUpdate adds a metadata update to the batch with deduplication based on timestamp. |
| 240 | func (b *Batcher) processUpdate(update update) { |
| 241 | ck := compositeKey{ |
| 242 | agentID: update.agentID, |
| 243 | key: update.key, |
| 244 | } |
| 245 | |
| 246 | // Check if key already exists and only update if new value is newer. |
| 247 | existing, exists := b.batch[ck] |
| 248 | if exists && update.collectedAt.Before(existing.collectedAt) { |
| 249 | return |
| 250 | } |
| 251 | |
| 252 | b.batch[ck] = value{ |
| 253 | v: update.v, |
| 254 | error: update.error, |
| 255 | collectedAt: update.collectedAt, |
| 256 | } |
| 257 | if !exists { |
| 258 | b.currentBatchLen.Add(1) |
| 259 | } |
| 260 | } |
| 261 | |
| 262 | // run runs the batcher loop, reading from the update channel and flushing |
| 263 | // periodically or when the batch reaches capacity. |
no test coverage detected