better handling
This commit is contained in:
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user