Fix: PDF is not cached#32678
Conversation
|
We don't have to manually clear the cached PDF because the app's |
| trustAllCerts={false} | ||
| renderActivityIndicator={() => <FullScreenLoadingIndicator />} | ||
| source={{uri: this.props.sourceURL}} | ||
| source={{uri: this.props.sourceURL, cache: true, expiration: 864000}} |
There was a problem hiding this comment.
@tienifr I think we should raise a discussion for the expiration interval. IMO 12 hours should be good.
There was a problem hiding this comment.
another question: will the cache be removed when attachment is deleted from the chat?
There was a problem hiding this comment.
will the cache be removed when attachment is deleted from the chat
Seems like it does not. But it still gets removed when we logged out.
There was a problem hiding this comment.
Seems like it does not. But it still gets removed when we logged out.
We should clear the cache when the attachment is deleted, and i am not sure how this will work incase of protected pdf i am checking.
|
@tienifr any updates on #32678 (comment)? |
|
Working on it. Seems like we still need Onyx. |
|
@tienifr Any updates? |
|
Code changes seem good but I'm trying to refactor to make it as short as possible. |
|
@tienifr any updates on this? |
|
I'm sorry will get this done today. |
|
@tienifr could we please get an update? ty! |
|
@getusha Sorry for the delay. This is ready for review. |
Reviewer Checklist
Screenshots/VideosAndroid: NativeScreen.Recording.2024-01-26.at.1.35.08.PM.movAndroid: mWeb ChromeScreen.Recording.2024-01-26.at.2.12.53.PM.moviOS: NativeScreen.Recording.2024-01-24.at.7.24.21.PM.moviOS: mWeb SafariScreen.Recording.2024-01-26.at.2.26.06.PM.movMacOS: Chrome / SafariScreen.Recording.2024-01-26.at.2.08.21.PM.movMacOS: DesktopScreen.Recording.2024-02-28.at.9.50.50.AM.mov |
|
@tienifr looks like we've got a conflict. |
| exists(path).then((exist) => { | ||
| if (!exist) { | ||
| resolve(); | ||
| } |
There was a problem hiding this comment.
Lets also update the list stored in Onyx
if (pdfPaths[path]) {
delete pdfPaths[path];
Onyx.set(ONYXKEYS.CACHED_PDF_PATHS, pdfPaths);
}|
There is also another case, when the pdf cached is sent from the other user and it gets deleted. |
|
@getusha I think that is infeasible. We don't even need to remove cache when delete attachment. IMO, the |
|
@tienifr any updates, looks like we've got a merge conflict. |
|
@tienifr gentle bump :) |
|
@tienifr any updates? |
|
I'm working on it. Wrapping up today. |
|
@tienifr lets get this done this week. |
|
Sorry I've been OOO the last week. This gets quite complicated and may introduce unnecessary and risky changes. Give me a day or two to do some tests. |
|
@tienifr we must complete this, this week 😄 |
|
@getusha I took a look at react-native-pdf's source code. The caching mechanism there is too simple. Whenever you open a file, it will check if the cache is expired then delete it and re-cache a new file. That means the cached file, once created, never goes away unless we log out. And the So if we want to remove the cache when expiration is over, we need to implement it ourself. The implementation is:
IMO, the implementation is quite complicated and not a good ROI (i.e. not brings much value). We'd better keep it simple and let they all be wiped out when signed out. What do you think? Do you want to go with it anw? |
I agree we should keep it simple, thanks for looking into that deeply. |
|
TS check failure is on |
| const encryptedSourceUrl = isAuthTokenRequired ? addEncryptedAuthTokenToURL(source) : source; | ||
|
|
||
| const onPDFLoadComplete = (path) => { | ||
| if (isUsedInCarousel && reportActionID && path) { |
There was a problem hiding this comment.
why is this? isUsedInCarousel, logged pdfPaths and it is not storing the paths anymore due to this condition.
There was a problem hiding this comment.
That's my fault. I removed it.
|
@getusha I also handled the case of deleting iou request with PDF receipt. |
MonilBhavsar
left a comment
There was a problem hiding this comment.
Thanks! Looks good to me
|
✋ This PR was not deployed to staging yet because QA is ongoing. It will be automatically deployed to staging after the next production release. |
|
🚀 Deployed to staging by https://github.com/MonilBhavsar in version: 1.4.45-0 🚀
|
|
🚀 Deployed to production by https://github.com/puneetlath in version: 1.4.45-6 🚀
|
Details
PDF files are not cached. This PR fixes that.
Fixed Issues
$ #32232
PROPOSAL: #32232 (comment)
Tests
Native only:
We can verify in the
Cachefolder of the app on native device that the cached PDF file is removed after logging out. We can manually log the file path infinishPDFLoadfunction to see where it's stored.Offline tests
NA
QA Steps
Native only:
PR Author Checklist
### Fixed Issuessection aboveTestssectionOffline stepssectionQA stepssectiontoggleReportand notonIconClick)myBool && <MyComponent />.src/languages/*files and using the translation methodWaiting for Copylabel for a copy review on the original GH to get the correct copy.STYLE.md) were followedAvatar, I verified the components usingAvatarare working as expected)/** comment above it */thisare necessary to be bound (i.e. avoidthis.submit = this.submit.bind(this);ifthis.submitis never passed to a component event handler likeonClick)StyleUtils.getBackgroundAndBorderStyle(themeColors.componentBG))Avataris modified, I verified thatAvataris working as expected in all cases)ScrollViewcomponent to make it scrollable when more elements are added to the page.mainbranch was merged into this PR after a review, I tested again and verified the outcome was still expected according to theTeststeps.Screenshots/Videos
Android: Native
Screen.Recording.2023-12-07.at.22.57.03-compressed.mov
Android: mWeb Chrome
iOS: Native
Screen.Recording.2023-12-07.at.22.53.29-compressed.mov
Screen.Recording.2023-12-07.at.22.54.07-compressed.mov
iOS: mWeb Safari
MacOS: Chrome / Safari
Screen.Recording.2023-12-07.at.22.50.55-compressed.mov
MacOS: Desktop