-
Notifications
You must be signed in to change notification settings - Fork 2.9k
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
[$500] Chat - The video is reloaded every time you open it #37168
Comments
Job added to Upwork: https://www.upwork.com/jobs/~018db53b84762ad824 |
Triggered auto assignment to Contributor-plus team member for initial proposal review - @DylanDylann ( |
Triggered auto assignment to @greg-schroeder ( |
👋 Friendly reminder that deploy blockers are time-sensitive ⏱ issues! Check out the open `StagingDeployCash` deploy checklist to see the list of PRs included in this release, then work quickly to do one of the following:
|
Triggered auto assignment to @Gonals ( |
We think that this bug might be related to #vip-vsb |
This shows no caching in the app. |
📣 @webbdays! 📣
|
ProposalPlease re-state the problem that we are trying to solve in this issue.The problem we are trying to solve is that the video attachment in the chat is reloaded every time it is opened, instead of being cached after the first load. This results in unnecessary network requests and a suboptimal user experience. This only happens on the mobile version of the app. What is the root cause of that problem?The root cause of the problem is that the video is not being cached on the device after the first load in the
What changes do you think we should make in order to solve the problem?To solve the problem, we should implement a caching mechanism for the video files. When a video is opened for the first time, it should be downloaded and cached on the device. Subsequent openings of the video should use the cached version instead of fetching it from the server again. Thankfully, since we are already using expo, we can just make use of expo's file system.
import * as FileSystem from 'expo-file-system';
const MAX_CACHE_SIZE = 500 * 1024 * 1024; // 500MB
const CACHE_DIR = `${FileSystem.cacheDirectory}videos/`;
const fetchAndCacheVideo = async (videoUri) => {
const fileName = videoUri.split('/').pop();
const videoPath = `${CACHE_DIR}${fileName}`;
// Check if the video is already cached
const isCached = await FileSystem.getInfoAsync(videoPath).then(
(fileInfo) => fileInfo.exists
);
if (isCached) {
// Load the cached video
return videoPath;
} else {
// Ensure the cache directory exists
await FileSystem.makeDirectoryAsync(CACHE_DIR, { intermediates: true });
// Check available space and clean cache if needed
await cleanCacheIfNeeded();
// Fetch and cache the video
const downloadResult = await FileSystem.downloadAsync(
videoUri,
videoPath
);
if (downloadResult.status === 200) {
return videoPath;
} else {
throw new Error('Failed to fetch video');
}
}
};
const getCacheSize = async () => {
const files = await FileSystem.readDirectoryAsync(CACHE_DIR);
const sizes = await Promise.all(
files.map(file => FileSystem.getInfoAsync(`${CACHE_DIR}${file}`))
);
return sizes.reduce((total, {size}) => total + size, 0);
};
const cleanCacheIfNeeded = async () => {
const cacheSize = await getCacheSize();
if (cacheSize > MAX_CACHE_SIZE) {
const files = await FileSystem.readDirectoryAsync(CACHE_DIR);
const fileInfos = await Promise.all(
files.map(file => FileSystem.getInfoAsync(`${CACHE_DIR}${file}`))
);
// Sort by modificationTime ascending to remove oldest first
fileInfos.sort((a,b) => a.modificationTime - b.modificationTime);
let sizeToClear = cacheSize - MAX_CACHE_SIZE;
for (const {uri, size} of fileInfos) {
await FileSystem.deleteAsync(uri);
sizeToClear -= size;
if (sizeToClear <= 0) {
break;
}
}
}
}; The UPDATE: Two new utility functions are added:
This approach limits the video cache to a maximum size and automatically removes the oldest cached videos when that limit is reached. The specific size limit and cache location can be adjusted as needed. |
Note: Second when we add caching, cache invalidation is very important. Adding functionality like ask the server "is the video/file modified?" before asking for video. (This needs some server side changes(very minor)). |
@izarutskaya @DylanDylann @greg-schroeder I'm not sure if it is a bug, I think it is more like a new feature for the video player. The presented behavior is correct according to the video player design doc. Video caching wasn't planned during the predesign. I think it might be a great improvement! What do you think about it @francoisl? @brandonhenry video player work differently depending on the screen size. On small screens, they are only usable inside the attachment modal. On large screens video players are available inside chat. When extending the video we are sharing the component to the attachment carousel to optimize video loadings (currently it is broken on main but I created a fix for it). Because of that, I think we should cache only videos that have |
📣 It's been a week! Do we have any satisfactory proposals yet? Do we need to adjust the bounty for this issue? 💸 |
@Gonals @greg-schroeder @DylanDylann this issue is now 3 weeks old. There is one more week left before this issue breaks WAQ and will need to go internal. What needs to happen to get a PR in review this week? Please create a thread in #expensify-open-source to discuss. Thanks! |
conversation ongoing |
Discussing on Slack |
📣 It's been a week! Do we have any satisfactory proposals yet? Do we need to adjust the bounty for this issue? 💸 |
@DylanDylann |
Discussing on Slack |
This might be moved |
📣 It's been a week! Do we have any satisfactory proposals yet? Do we need to adjust the bounty for this issue? 💸 |
@francoisl We decided to handle this issue internally. Should we close this one? |
I'm going to close it per that discussion ... please reopen if you disagree. |
Issue is still reproducible on the latest build 1.4.74-0 vide.mp4 |
Thanks @lanitochka17 - we're just handling it in the linked issue above, so we can leave this closed. |
If you haven’t already, check out our contributing guidelines for onboarding and email [email protected] to request to join our Slack channel!
Found when validating PR : #37036
Version Number: v1.4.43-18
Reproducible in staging?: Y
Reproducible in production?: N
Email or phone of affected tester (no customers): [email protected]
Logs: https://stackoverflow.com/c/expensify/questions/4856
Expensify/Expensify Issue URL:
Issue reported by: Applause-Internal Team
Slack conversation:
Action Performed:
Expected Result:
Loading spinner is displayed only when you open the video for the first time
Actual Result:
The video is reloaded every time you open it
Workaround:
Unknown
Platforms:
Which of our officially supported platforms is this issue occurring on?
Screenshots/Videos
Bug6390764_1708771155473.Record_2024-02-23-23-25-53_4f9154176b47c00da84e32064abf1c48.mp4
View all open jobs on GitHub
Upwork Automation - Do Not Edit
The text was updated successfully, but these errors were encountered: