in src/app/backend/resource/logs/logs.go [189:220]
func (self LogLines) getLineIndex(logLineId *LogLineId) int {
if logLineId == nil || logLineId.LogTimestamp == NewestTimestamp || len(self) == 0 || logLineId.LogTimestamp == "" {
// if no line id provided return index of last item.
return len(self) - 1
} else if logLineId.LogTimestamp == OldestTimestamp {
return 0
}
logTimestamp := logLineId.LogTimestamp
matchingStartedAt := 0
matchingStartedAt = sort.Search(len(self), func(i int) bool {
return self[i].Timestamp >= logTimestamp
})
linesMatched := 0
if matchingStartedAt < len(self) && self[matchingStartedAt].Timestamp == logTimestamp { // match found
for (matchingStartedAt+linesMatched) < len(self) && self[matchingStartedAt+linesMatched].Timestamp == logTimestamp {
linesMatched += 1
}
}
var offset int
if logLineId.LineNum < 0 {
offset = linesMatched + logLineId.LineNum
} else {
offset = logLineId.LineNum - 1
}
if 0 <= offset && offset < linesMatched {
return matchingStartedAt + offset
}
return LineIndexNotFound
}