better handling

This commit is contained in:
2026-04-05 09:47:25 +02:00
parent 0fd17e4944
commit 988ea1d919
5 changed files with 357 additions and 282 deletions
+12 -2
View File
@@ -98,7 +98,11 @@ func (c *Collector) Subscribe(filter func(websocket.HistoryEntry) bool) (chan we
return ch, cleanup
}
func (c *Collector) GetHistory() []websocket.HistoryEntry {
func (c *Collector) GetHistory(limit int) []websocket.HistoryEntry {
if limit <= 0 {
limit = c.historySize
}
c.historyMutex.RLock()
defer c.historyMutex.RUnlock()
@@ -108,6 +112,12 @@ func (c *Collector) GetHistory() []websocket.HistoryEntry {
history = append(history, entry)
}
})
// Return only the last 'limit' items if we have more
if len(history) > limit {
history = history[len(history)-limit:]
}
return history
}
@@ -121,7 +131,7 @@ func (c *Collector) SearchHistory(ctx context.Context, query string, limit int)
}
// Fallback to in-memory if no store
history := c.GetHistory()
history := c.GetHistory(limit)
var filtered []websocket.HistoryEntry
// Lowercase query for case-insensitive search
lowerQuery := strings.ToLower(query)