Skip to content

[ES|QL] Store more than 20 queries in the history#232955

Merged
stratoula merged 12 commits intoelastic:mainfrom
stratoula:more-items-history-component
Aug 27, 2025
Merged

[ES|QL] Store more than 20 queries in the history#232955
stratoula merged 12 commits intoelastic:mainfrom
stratoula:more-items-history-component

Conversation

@stratoula
Copy link
Contributor

@stratoula stratoula commented Aug 26, 2025

Summary

Closes #225661

image

It allows to store more than 20 queries. It now relies on a local storage size (50KB) which is again conservative but allows to store more than 20 queries. Apporximately:

Short queries: Up to ~330 queries (if they average 150 bytes)
Long queries: ~200-250 queries

I also added a search input in the history tab to be easier to find them (as the number of stored queries is bigger now)

Checklist

@stratoula stratoula added Feature:ES|QL ES|QL related features in Kibana Team:ESQL ES|QL related features in Kibana t// v9.2.0 release_note:enhancement backport:skip This PR does not require backporting labels Aug 27, 2025
@stratoula stratoula requested a review from andreadelrio August 27, 2025 08:08
@stratoula stratoula marked this pull request as ready for review August 27, 2025 08:08
@stratoula stratoula requested a review from a team as a code owner August 27, 2025 08:08
@elasticmachine
Copy link
Contributor

Pinging @elastic/kibana-esql (Team:ESQL)

Copy link
Contributor

@bartoval bartoval left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ just some cosmetic comment and a curiosity


return {
queryCount: queries.length,
storageSizeKB: Math.round(storageSizeKB * 100) / 100, // Round to 2 decimals
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cosmetic Nit: storageSizeKB: storageSizeKB.toFixed(2) (or parseFloat(storageSizeKB.toFixed(2)) if you want a number )

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems cleaner, I did it 2400f3a

allQueries = sortedByDate.slice(0, maxQueriesAllowed);
if (storageSizeKB > MAX_STORAGE_SIZE_KB && queryList.length > 10) {
// Remove oldest queries until under size limit or minimum count
const sortedByDate = queryList.sort((a, b) => sortDates(b.timeRan, a.timeRan));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just a curiosity: From a test deleted in this diff, I see that timeRan is something like timeRan: 'Mar. 25, 24 08:45:27',
If this is true, I think the current implementation of sortDates is going to fail because it compare strings.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The timeRan is already converted to date ISO string format so this works fine

queryCount: queries.length,
storageSizeKB: Math.round(storageSizeKB * 100) / 100, // Round to 2 decimals
maxStorageLimitKB: MAX_STORAGE_SIZE_KB,
storageUsagePercent: Math.round((storageSizeKB / MAX_STORAGE_SIZE_KB) * 10000) / 100, // Round to 2 decimals
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cosmetic Nit: storageUsagePercent: Math.round((storageSizeKB / MAX_STORAGE_SIZE_KB) * 100).toFixed(2) (or parseFloat(...)

Copy link
Contributor Author

@stratoula stratoula Aug 27, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done 43d81ab

if (allQueries.length >= maxQueriesAllowed + 1) {
const sortedByDate = allQueries.sort((a, b) => sortDates(b.timeRan, a.timeRan));
// Check storage size and trim if needed
const checkAndTrimBySize = (queryList: QueryHistoryItem[]): QueryHistoryItem[] => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cosmetic Nit: alterative without recursion, and querylist mutation

    const checkAndTrimBySize = (queryList: QueryHistoryItem[]): QueryHistoryItem[] => {
    let list = [...queryList].sort((a, b) => sortDates(b.timeRan, a.timeRan));

    const sizeKB = arr => new Blob([JSON, stringify(arr)]).size / 1024;

    while (sizeKB(list) > MAX_STORAGE_SIZE_KB && list.length > 10) {
      list.pop()
    }

    return list
  }
Copy link
Contributor Author

@stratoula stratoula Aug 27, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think I prefer the current one so I will stick with it

@elasticmachine
Copy link
Contributor

💛 Build succeeded, but was flaky

Failed CI Steps

Test Failures

  • [job] [logs] Jest Tests #20 / initializeESQLControlSelections values from query should load availableOptions but not serialize them

Metrics [docs]

Async chunks

Total size of all lazy-loaded chunks that will be downloaded as the user navigates the app

id before after diff
esql 265.5KB 267.0KB +1.4KB

History

@andreadelrio
Copy link
Contributor

@stratoula What do you think of swapping the search bar with the "Showing x results (size)" text and setting a fixed width on the search bar? I think it'd look nice and would prevent the slight layout shift that we have now when switching tabs.

Frame 1321315200
@stratoula
Copy link
Contributor Author

@andreadelrio sure! Done fcff4d4

It feels better, I agree!

Copy link
Contributor

@andreadelrio andreadelrio left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Design changes LGTM. Thanks! Nice feature!

@stratoula stratoula enabled auto-merge (squash) August 27, 2025 14:37
@stratoula stratoula merged commit 7e7f636 into elastic:main Aug 27, 2025
13 checks passed
kowalczyk-krzysztof pushed a commit to kowalczyk-krzysztof/kibana that referenced this pull request Aug 30, 2025
## Summary

Closes elastic#225661

<img width="922" height="234" alt="image"
src="https://github.com/user-attachments/assets/40937b86-df6e-4048-9cc6-29888e51d7bb"
/>


It allows to store more than 20 queries. It now relies on a local
storage size (50KB) which is again conservative but allows to store more
than 20 queries. Apporximately:

Short queries: Up to ~330 queries (if they average 150 bytes)
Long queries: ~200-250 queries

I also added a search input in the history tab to be easier to find them
(as the number of stored queries is bigger now)

### Checklist

- [ ] [Unit or functional
tests](https://www.elastic.co/guide/en/kibana/master/development-tests.html)
were updated or added to match the most common scenarios
qn895 pushed a commit to qn895/kibana that referenced this pull request Sep 2, 2025
## Summary

Closes elastic#225661

<img width="922" height="234" alt="image"
src="https://github.com/user-attachments/assets/40937b86-df6e-4048-9cc6-29888e51d7bb"
/>


It allows to store more than 20 queries. It now relies on a local
storage size (50KB) which is again conservative but allows to store more
than 20 queries. Apporximately:

Short queries: Up to ~330 queries (if they average 150 bytes)
Long queries: ~200-250 queries

I also added a search input in the history tab to be easier to find them
(as the number of stored queries is bigger now)

### Checklist

- [ ] [Unit or functional
tests](https://www.elastic.co/guide/en/kibana/master/development-tests.html)
were updated or added to match the most common scenarios
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

backport:skip This PR does not require backporting Feature:ES|QL ES|QL related features in Kibana needs_docs release_note:enhancement Team:ESQL ES|QL related features in Kibana t// v9.2.0

5 participants