Skip to content
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

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

sejli
Copy link
Member

@sejli sejli commented Sep 18, 2024

Description

  • Stores last cache updated time in session storage. Last updated time refers to the last time that the cache was updated across all datasets (overall cache rather than specific types).
  • Adds display for last cache update time in Advanced Dataset Selector
  • Adds refresh cache button which clears session storage

Still early implementation, open to suggestions

Issues Resolved

Screenshot

Empty Cache State:

image

Cache has been populated:

image

Testing the changes

Changelog

  • feat: Add last updated time and cache refresh button to Discover Advanced Dataset Selector

Check List

  • All tests pass
    • yarn test:jest
    • yarn test:jest_integration
  • New functionality includes testing.
  • New functionality has been documented.
  • Update CHANGELOG.md
  • Commits are signed per the DCO using --signoff

Signed-off-by: Sean Li <lnse@amazon.com>
Copy link

codecov bot commented Sep 18, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 64.05%. Comparing base (b826df8) to head (511ee18).
Report is 19 commits behind head on main.

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     
Flag Coverage Δ
Linux_1 30.04% <0.00%> (-0.02%) ⬇️
Linux_2 58.85% <0.00%> (+0.02%) ⬆️
Linux_3 40.34% <100.00%> (-0.04%) ⬇️
Linux_4 31.43% <0.00%> (-0.03%) ⬇️
Windows_1 30.06% <0.00%> (-0.02%) ⬇️
Windows_2 58.80% <0.00%> (+0.02%) ⬆️
Windows_3 40.35% <100.00%> (-0.03%) ⬇️
Windows_4 31.43% <0.00%> (-0.03%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@sejli sejli added backport 2.x discover for discover reinvent 2.17.1 labels Sep 18, 2024
Copy link
Collaborator

@virajsanghvi virajsanghvi left a 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 {
Copy link
Collaborator

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

Copy link
Member

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
Screenshot 2024-09-18 at 3 37 48 PM

@@ -92,6 +92,29 @@ export const DatasetExplorer = ({
</EuiLink>
</p>
</EuiText>
{queryString.getDatasetService().getLastCacheTime() && (
<EuiText>
Copy link
Collaborator

Choose a reason for hiding this comment

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

size='s'

@kavilla
Copy link
Member

kavilla commented Sep 18, 2024

a good catch all but did we want to consider making it more granular?

for example:
Screenshot 2024-09-18 at 3 26 56 PM

if i press the refresh on Data then it clears out the full cache. If i press refresh on Database then it will refresh all the Databases and Tables and not the Connections and Data Sources?

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 refresh = false but if the user presses the refresh button it will clear the cache related to the data structure passed in and it's children and refetch.

To get the date we could actually shove that in the data structure meta for when it was first fetched.

Copy link
Member

@kavilla kavilla left a 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());
Copy link
Collaborator

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.

Suggested change
this.setLastCacheTime(new Date());
this.setLastCacheTime(Date.now());

}

public getLastCacheTime(): string | undefined {
return this.sessionStorage.get('lastCacheTime');
Copy link
Collaborator

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

Suggested change
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 {
Copy link
Member

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

Copy link
Member

@kavilla kavilla left a 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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants