-
Notifications
You must be signed in to change notification settings - Fork 3k
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
Fix: PDF is not cached #32678
Fix: PDF is not cached #32678
Conversation
We don't have to manually clear the cached PDF because the app's |
@@ -155,7 +155,7 @@ class PDFView extends Component { | |||
fitPolicy={0} | |||
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Raised discussion on Slack.
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.
another question: will the cache be removed when attachment is deleted from the chat?
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.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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. |
src/libs/actions/CachedPDFPaths.ts
Outdated
exists(path).then((exist) => { | ||
if (!exist) { | ||
resolve(); | ||
} |
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.
Lets also update the list stored in Onyx
if (pdfPaths[path]) {
delete pdfPaths[path];
Onyx.set(ONYXKEYS.CACHED_PDF_PATHS, pdfPaths);
}
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.
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 |
@@ -153,6 +159,15 @@ function AttachmentView({ | |||
if ((_.isString(source) && Str.isPDF(source)) || (file && Str.isPDF(file.name || translate('attachmentView.unknownFilename')))) { | |||
const encryptedSourceUrl = isAuthTokenRequired ? addEncryptedAuthTokenToURL(source) : source; | |||
|
|||
const onPDFLoadComplete = (path) => { | |||
if (isUsedInCarousel && reportActionID && path) { |
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.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's my fault. I removed it.
@getusha I also handled the case of deleting iou request with PDF receipt. |
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.
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
Cache
folder of the app on native device that the cached PDF file is removed after logging out. We can manually log the file path infinishPDFLoad
function to see where it's stored.Offline tests
NA
QA Steps
Native only:
PR Author Checklist
### Fixed Issues
section aboveTests
sectionOffline steps
sectionQA steps
sectiontoggleReport
and notonIconClick
)myBool && <MyComponent />
.src/languages/*
files and using the translation methodWaiting for Copy
label for a copy review on the original GH to get the correct copy.STYLE.md
) were followedAvatar
, I verified the components usingAvatar
are working as expected)/** comment above it */
this
are necessary to be bound (i.e. avoidthis.submit = this.submit.bind(this);
ifthis.submit
is never passed to a component event handler likeonClick
)StyleUtils.getBackgroundAndBorderStyle(themeColors.componentBG)
)Avatar
is modified, I verified thatAvatar
is working as expected in all cases)ScrollView
component to make it scrollable when more elements are added to the page.main
branch was merged into this PR after a review, I tested again and verified the outcome was still expected according to theTest
steps.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