1
0
mirror of https://github.com/amir20/dozzle.git synced 2025-12-24 06:28:42 +01:00

fix: fixes pagination when logs are very long packed together. see #3373 (#3377)

This commit is contained in:
Amir Raminfar
2024-11-10 19:44:19 -08:00
committed by GitHub
parent f3cfe4f84d
commit d99964bbe7
2 changed files with 19 additions and 0 deletions

View File

@@ -161,6 +161,7 @@ function useLogStream(url: Ref<string>, loadMoreUrl?: Ref<string>) {
if (isLoadingMore.value) return;
const to = messages.value[0].date;
const lastSeenId = messages.value[0].id;
const last = messages.value[Math.min(messages.value.length - 1, 300)].date;
const delta = to.getTime() - last.getTime();
const from = new Date(to.getTime() + delta);
@@ -174,6 +175,7 @@ function useLogStream(url: Ref<string>, loadMoreUrl?: Ref<string>) {
loadMoreParams.append("from", from.toISOString());
loadMoreParams.append("to", to.toISOString());
loadMoreParams.append("minimum", "100");
loadMoreParams.append("lastSeenId", String(lastSeenId));
return withBase(`${loadMoreUrl.value}?${loadMoreParams.toString()}`);
});

View File

@@ -146,7 +146,19 @@ func (h *handler) fetchLogsBetweenDates(w http.ResponseWriter, r *http.Request)
levels[level] = struct{}{}
}
lastSeenId := uint32(0)
if r.URL.Query().Has("lastSeenId") {
to = to.Add(50 * time.Millisecond) // Add a little buffer to ensure we get the last event
num, err := strconv.ParseUint(r.URL.Query().Get("lastSeenId"), 10, 32)
if err != nil {
http.Error(w, err.Error(), http.StatusBadRequest)
return
}
lastSeenId = uint32(num)
}
encoder := json.NewEncoder(w)
outer:
for {
if buffer.Len() > minimum {
break
@@ -185,6 +197,11 @@ func (h *handler) fetchLogsBetweenDates(w http.ResponseWriter, r *http.Request)
continue
}
if lastSeenId != 0 && event.Id == lastSeenId {
log.Debug().Uint32("lastSeenId", lastSeenId).Msg("found last seen id")
break outer
}
buffer.Push(event)
}