MCPcopy Index your code
hub / github.com/riverqueue/river / getKeepStart

Function getKeepStart

riverlog/river_log.go:294–328  ·  view source on GitHub ↗
(bounds []arrayElementBounds, newEntryLen, maxTotalBytes int)

Source from the content-addressed store, hash-verified

292}
293
294func getKeepStart(bounds []arrayElementBounds, newEntryLen, maxTotalBytes int) int {
295 if maxTotalBytes <= 0 {
296 return 0
297 }
298
299 // Keep newest entry even if it's larger than the configured cap.
300 newOnlyLen := 2 + newEntryLen // `[` + entry + `]`
301 if newOnlyLen > maxTotalBytes {
302 return len(bounds)
303 }
304
305 if len(bounds) == 0 {
306 return 0
307 }
308
309 lastEnd := bounds[len(bounds)-1].End
310
311 // Iterate from oldest to newest so we drop the minimum number of entries
312 // necessary to fit the configured cap.
313 for keepStart := 0; keepStart <= len(bounds); keepStart++ {
314 contentLen := newEntryLen
315 if keepStart < len(bounds) {
316 // Use actual byte offsets from parsed elements so separator
317 // whitespace is fully counted toward the cap.
318 keptContentLen := lastEnd - bounds[keepStart].Start
319 contentLen += 1 + keptContentLen // comma between kept suffix and new entry
320 }
321 totalLen := 2 + contentLen // `[` + content + `]`
322 if totalLen <= maxTotalBytes {
323 return keepStart
324 }
325 }
326
327 return len(bounds)
328}
329
330func buildAppendedArray(existingArrayBytes []byte, bounds []arrayElementBounds, keepStart int, newEntryBytes []byte) []byte {
331 totalLen := 0

Callers 1

appendLogDataWithCapFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…