-
Notifications
You must be signed in to change notification settings - Fork 867
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Discover] Display Cache Time and Clear Cache Button #8214
base: main
Are you sure you want to change the base?
Conversation
Signed-off-by: Sean Li <lnse@amazon.com>
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #8214 +/- ##
=======================================
Coverage 64.05% 64.05%
=======================================
Files 3741 3741
Lines 88629 88688 +59
Branches 13801 13818 +17
=======================================
+ Hits 56771 56813 +42
- Misses 31260 31263 +3
- Partials 598 612 +14
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should we add tests for new methods + snapshot test to bump up patch cov?
this.sessionStorage.clear(); | ||
} | ||
|
||
public getLastCacheTime(): string | undefined { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
want to convert to a Date given its passed a date? otherwise consumers just need to handle this
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yeah we should make sure to do this.
@sejli
we should probably include the day and should also pulling from UI Settings to get the format of the date
@@ -92,6 +92,29 @@ export const DatasetExplorer = ({ | |||
</EuiLink> | |||
</p> | |||
</EuiText> | |||
{queryString.getDatasetService().getLastCacheTime() && ( | |||
<EuiText> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
size='s'
src/plugins/data/public/query/query_string/dataset_service/dataset_service.ts
Outdated
Show resolved
Hide resolved
a good catch all but did we want to consider making it more granular? if i press the refresh on This way to avoid destroying the cache if only one source is out of date? If so then we can consider extending this function https://github.com/opensearch-project/OpenSearch-Dashboards/blob/main/src/plugins/data/public/query/query_string/dataset_service/dataset_service.ts#L91 to have a new boolean as a param like To get the date we could actually shove that in the data structure meta for when it was first fetched. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
+1 to @virajsanghvi comments. nothing blocking
Signed-off-by: Sean Li <lnse@amazon.com>
@@ -138,6 +138,7 @@ export class DatasetService { | |||
} | |||
|
|||
private cacheDataStructure(dataType: string, dataStructure: DataStructure) { | |||
this.setLastCacheTime(new Date()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since this is getting set in the sessionStorage, the Date object gets converted to a string. To consume this, we will need to parse it and what not. To programmatically use date, it is best to stick with the unix timestamp of the date which is number and can be easily parsed and formatted.
this.setLastCacheTime(new Date()); | |
this.setLastCacheTime(Date.now()); |
} | ||
|
||
public getLastCacheTime(): string | undefined { | ||
return this.sessionStorage.get('lastCacheTime'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Assuming you do use Date.now()
this line changes to
return this.sessionStorage.get('lastCacheTime'); | |
return Number(this.sessionStorage.get('lastCacheTime')) || undefined; |
The reason I propose Number
and not parseInt
is that parseInt
will try to parse the numeric part of a mixed alphanumeric string which we don't want because the value should be fully numeric, and if it is not, we need to fail to parse.
The reason for || undefined
is that we should return undefined
for all invalid values: NaN
and 0
.
Signed-off-by: Sean Li <lnse@amazon.com>
this.sessionStorage.clear(); | ||
} | ||
|
||
public getLastCacheTime(): number | undefined { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit i think there is precedent with updatedAt
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
agreeing with @virajsanghvi with some snapshots will be awesome.
one nit with the naming of the field
one fast follow we should do is pull from ui settings for the date format
Description
Still early implementation, open to suggestions
Issues Resolved
Screenshot
Empty Cache State:
Cache has been populated:
Testing the changes
Changelog
Check List
yarn test:jest
yarn test:jest_integration