[ES|QL] Store more than 20 queries in the history#232955
[ES|QL] Store more than 20 queries in the history#232955stratoula merged 12 commits intoelastic:mainfrom
Conversation
|
Pinging @elastic/kibana-esql (Team:ESQL) |
|
|
||
| return { | ||
| queryCount: queries.length, | ||
| storageSizeKB: Math.round(storageSizeKB * 100) / 100, // Round to 2 decimals |
There was a problem hiding this comment.
cosmetic Nit: storageSizeKB: storageSizeKB.toFixed(2) (or parseFloat(storageSizeKB.toFixed(2)) if you want a number )
| 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)); |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
cosmetic Nit: storageUsagePercent: Math.round((storageSizeKB / MAX_STORAGE_SIZE_KB) * 100).toFixed(2) (or parseFloat(...)
| 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[] => { |
There was a problem hiding this comment.
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
}There was a problem hiding this comment.
I think I prefer the current one so I will stick with it
💛 Build succeeded, but was flaky
Failed CI StepsTest Failures
Metrics [docs]Async chunks
History
|
|
@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.
|
|
@andreadelrio sure! Done fcff4d4 It feels better, I agree! |
andreadelrio
left a comment
There was a problem hiding this comment.
Design changes LGTM. Thanks! Nice feature!
## 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
## 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

Summary
Closes #225661
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