-
Notifications
You must be signed in to change notification settings - Fork 5
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
feat: andrel - 185 general refactors #187
Conversation
Screen.Recording.2023-03-15.at.1.58.34.PM.mov
is only called when we run |
Deploying with
|
Latest commit: |
58e68c8
|
Status: | ✅ Deploy successful! |
Preview URL: | https://7b51cb07.keypom-airfoil.pages.dev |
Branch Preview URL: | https://andrel-185-general-refactors.keypom-airfoil.pages.dev |
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.
Looks good overall but I'd like to suggest the drop store for the caching mechanism. Let me know your thoughts!
src/lib/keypom.ts
Outdated
@@ -66,6 +66,16 @@ class KeypomJS { | |||
this.nearConnection = await connect(connectionConfig); | |||
}; | |||
|
|||
dropInformationMeta: { |
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.
this object should be placed above constructor for consistency
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.
Currently, we are only storing all drops. I think we should also store drop information (getDropInformation).
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.
The current logic works, but I wanna extend the caching mechanism to Drop Manager as well. In addition, if we're caching the data here, I suggest we create something like a Redux store here to handle 2 scenarios.
-
get all drops, after rpc calling getDrops, we populate the ids OR only store properties required by AllDrops table (drop_id, metadata, next_key_id) in dropStore.paginatedDrops. Set expiry time for getDrops.
-
user clicks on a drop, in Drop Manager, page component will get the drop from the store
Suggestions:
// drop store structure
const dropStore = {
paginatedDrops: {
// pageIndex => array of dropIds or partial drop object
1: ['dropid-1', 'dropid-2', ...],
2: ['dropid-11', 'dropid-12', ...],
},
drops: {
// dropId => dropData
'dropid-1': {
rop_id: 'dropid-1',
config: {},
...
},
'dropid-2': {
drop_id: 'dropid-2',
config: {},
...
},
},
getDropsExpiryTime: 16334382,
};
// in getDrops()
// setting cache expiry time for getDrops
const CACHE_MAX_AGE = 5000; // ms
const newGetDropsExpiryTime = new Date(new Date().getTime() + CACHE_MAX_AGE).getTime();
// comparing current time and expiry time
if (Date.now() > getDropsExpiryTime) {
// getDropsExpired
// reset store
// fetch the drops again
}
what do you think?
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.
Also i prefer the expiry/max-age approach/terminologies, just referencing Cache control mechanism in http headers
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.
agree with the terminologies. will make some changes to this. However, i'd stick with Date.now()
compared to new Date().getTime()
for performance reason 👍
src/lib/keypom.ts
Outdated
this.dropStore.paginatedDrops[dropId] = { | ||
...(await this.getDropInfo({ dropId })), | ||
getPageIndex: pageIndex, | ||
getExpiryTime: newGetPaginatedDropsExpiryTime, |
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.
sorry my bad, can we remove get
from the variable names. getXX
sounds like a function name
src/lib/keypom.ts
Outdated
const newGetDropsExpiryTime = new Date(Date.now() + CACHE_MAX_AGE).getTime(); | ||
this.dropStore.getDropsExpiryTime = newGetDropsExpiryTime; | ||
|
||
this.dropStore.getDropsLastPage = start; |
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.
getDropsLastPage
a bit confused by this, is it referencing the current last item index?
src/lib/keypom.ts
Outdated
@@ -190,7 +207,21 @@ class KeypomJS { | |||
return null; | |||
}; | |||
|
|||
getDrops = async ({ accountId, start, limit }) => await getDrops({ accountId, start, limit }); | |||
getDrops = async ({ accountId, start, limit }) => { |
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.
getDrops = async ({ accountId, start, limit }) => { | |
getDrops = async ({ accountId, start, limit }: { account: string; start: string | number; limit: number; }) => { |
src/lib/keypom.ts
Outdated
/** Get Drops caching logic */ | ||
if ( | ||
Date.now() > this.dropStore.getDropsExpiryTime || | ||
start !== this.dropStore.getDropsLastPage |
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.
i tested locally, if I paginate to next page (page 1 -> 2), then back to previous (2 -> 1), it's not showing the previous drops from store (1)
@andrehadianto works very well when i go to a drop manager from all drops page and back to all drops on page 1. But i think we should cache all paginated drops. All scenarios before expiry time.
Scenario 2:
My suggestion would be to concatenate
|
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.
Looks good! thanks for working on this
Description
This PR handles:
Fixes #185
How to test
Buttons storybook
yarn run storybook
localhost:3000
Add cache control:
My Drops
using the navigation button (to prevent reloading)Screenshots/Screen Recording of Implementation
See comments