mirror of
https://github.com/amir20/dozzle.git
synced 2025-12-24 14:31:44 +01:00
fix: improves search on initital load (#3253)
This commit is contained in:
@@ -168,7 +168,7 @@ function useLogStream(url: Ref<string>, loadMoreUrl?: Ref<string>) {
|
||||
fetchingInProgress = true;
|
||||
try {
|
||||
const stopWatcher = watchOnce(url, () => abortController.abort("stream changed"));
|
||||
const moreParams = { ...params.value, from: from.toISOString(), to: to.toISOString(), fill: "1" };
|
||||
const moreParams = { ...params.value, from: from.toISOString(), to: to.toISOString(), minimum: "100" };
|
||||
const logs = await (
|
||||
await fetch(withBase(`${loadMoreUrl.value}?${new URLSearchParams(moreParams).toString()}`), { signal })
|
||||
).text();
|
||||
|
||||
@@ -5,6 +5,7 @@ import (
|
||||
"context"
|
||||
"errors"
|
||||
"regexp"
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
"github.com/goccy/go-json"
|
||||
@@ -117,10 +118,27 @@ func (h *handler) fetchLogsBetweenDates(w http.ResponseWriter, r *http.Request)
|
||||
}
|
||||
}
|
||||
|
||||
minimum := 0
|
||||
if r.URL.Query().Has("minimum") {
|
||||
minimum, err = strconv.Atoi(r.URL.Query().Get("minimum"))
|
||||
if err != nil {
|
||||
http.Error(w, err.Error(), http.StatusBadRequest)
|
||||
return
|
||||
}
|
||||
|
||||
if minimum < 0 || minimum > buffer.Size {
|
||||
http.Error(w, errors.New("minimum must be between 0 and buffer size").Error(), http.StatusBadRequest)
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
for {
|
||||
if buffer.Len() > 0 {
|
||||
if buffer.Len() > minimum {
|
||||
break
|
||||
}
|
||||
|
||||
buffer.Clear()
|
||||
|
||||
events, err := containerService.LogsBetweenDates(r.Context(), from, to, stdTypes)
|
||||
if err != nil {
|
||||
log.Error().Err(err).Msg("error fetching logs")
|
||||
@@ -138,10 +156,6 @@ func (h *handler) fetchLogsBetweenDates(w http.ResponseWriter, r *http.Request)
|
||||
}
|
||||
}
|
||||
|
||||
if !r.URL.Query().Has("fill") { // only auto fill if fill query parameter is set
|
||||
break
|
||||
}
|
||||
|
||||
from = from.Add(-delta)
|
||||
delta = delta * 2
|
||||
|
||||
|
||||
Reference in New Issue
Block a user