Skip to content

Commit

Permalink
elastic: fix events pagination
Browse files Browse the repository at this point in the history
The previous commit only fixed event pagination for SQLite. The search
parameters were not being set for Elastic.

Also, cleanup the URLs in event pagination by removing characters that
would get escaped in the URL.
  • Loading branch information
jasonish committed Dec 27, 2024
1 parent c52280f commit 461d6cf
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 6 deletions.
5 changes: 4 additions & 1 deletion src/datetime.rs
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,10 @@ mod test {

#[test]
fn test_parse() {
let _ts = parse("2024-05-16T16:08:17.876423-0600", None).unwrap();
let ts0 = parse("2024-05-16T16:08:17.876423-0600", None).unwrap();
let ts1 = parse("20240516T160817.876423-0600", None).unwrap();
assert_eq!(ts0, ts1);

let _ts = parse("2023-01-01T01:02:00.0+0000", None).unwrap();
let _ts = parse("2024-05-16T16:08:17.876423+0600", None).unwrap();
let _ts = parse("2024-05-16T16:08:17.876423Z", None).unwrap();
Expand Down
4 changes: 2 additions & 2 deletions src/elastic/eventrepo/events.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,11 @@ impl ElasticEventRepo {
);

if let Some(ts) = params.from {
warn!("Unexpected min_timestamp of {}", &ts);
filters.push(request::timestamp_gte_filter(&ts));
}

if let Some(ts) = params.to {
warn!("Unexpected max_timestamp of {}", &ts);
filters.push(request::timestamp_lte_filter(&ts));
}

let sort_by = params.sort_by.unwrap_or_else(|| "@timestamp".to_string());
Expand Down
15 changes: 12 additions & 3 deletions webapp/src/Events.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,10 @@ export function Events() {
}

function gotoNewer() {
const timestamp = events()[0]._source["@timestamp"];
// Removing "-" and ":" are for URL tidyness, but don't matter.
const timestamp = events()[0]
._source["@timestamp"].replace(/(\d{4})-(\d{2})-(\d{2})/, "$1$2$3")
.replaceAll(":", "");
setSearchParams({
order: "asc",
from: timestamp,
Expand All @@ -214,7 +217,13 @@ export function Events() {
}

function gotoOlder() {
const timestamp = events()[events().length - 1]._source["@timestamp"];
// Removing "-" and ":" are for URL tidyness, but don't matter.
const timestamp = events()
[events().length - 1]._source["@timestamp"].replace(
/(\d{4})-(\d{2})-(\d{2})/,
"$1$2$3"
)
.replaceAll(":", "");
setSearchParams({
order: undefined,
from: undefined,
Expand All @@ -225,7 +234,7 @@ export function Events() {
function gotoNewest() {
setSearchParams({
order: undefined,
to: undefined,
max_timestamp: undefined,
from: undefined,
});
}
Expand Down

0 comments on commit 461d6cf

Please sign in to comment.