Skip to content

armgit / ente

Public Imported from GitHub
0

πŸ’š End-to-end encrypted cloud for everything.

Outline

Manav Rathi864f0317fa0c
diff --git a/web/packages/gallery/components/viewer/data-source.ts b/web/packages/gallery/components/viewer/data-source.ts
index 933e66d5bc..9c57213049 100644
--- a/web/packages/gallery/components/viewer/data-source.ts
+++ b/web/packages/gallery/components/viewer/data-source.ts
@@ -251,7 +251,7 @@ export const fileViewerDidClose = () => {
resetState();
} else {
// Selectively clear.
- forgetFailedItems();
+ forgetFailedOrTransientItems();
forgetExif();
}
};
@@ -357,12 +357,18 @@ export const forgetItemDataForFileID = (fileID: number) => {
};
/**
- * Forget item data for the given {@link file} if its fetch had failed.
+ * Forget item data for the given {@link file} if its fetch had failed, or if it
+ * is caching something that is transient in nature.
*
- * This is called when the user moves away from a slide so that we attempt a
- * full retry when they come back the next time.
+ * It is called when the user moves away from a slide. In particular, this way
+ * we can reset failures, if any, for a slide so that the fetch is tried again
+ * when we come back to it.
+ *
+ * See: [Note: File viewer error handling]
+ *
+ * See: [Note: Caching HLS playlist data]
*/
-export const forgetFailedItemDataForFileID = (fileID: number) => {
+export const forgetItemDataForFileIDIfNeeded = (fileID: number) => {
if (_state.itemDataByFileID.get(fileID)?.fetchFailed)
forgetItemDataForFileID(fileID);
};
@@ -381,13 +387,17 @@ export const updateItemDataAlt = (updatedFile: EnteFile) => {
};
/**
- * Forget item data for the all files whose fetch had failed.
+ * Forget item data for the all files whose fetch had failed, or if the
+ * corresponding item data is transient and shouldn't be cached.
*
- * This is called when the user closes the file viewer so that we attempt a full
- * retry when they reopen the viewer the next time.
+ * This is called when the user closes the file viewer; in particular, this way
+ * we attempt a full retry for previously failed files when the user reopens the
+ * viewer the next time.
*/
-const forgetFailedItems = () =>
- [..._state.itemDataByFileID.keys()].forEach(forgetFailedItemDataForFileID);
+const forgetFailedOrTransientItems = () =>
+ [..._state.itemDataByFileID.keys()].forEach(
+ forgetItemDataForFileIDIfNeeded,
+ );
const enqueueUpdates = async (
file: EnteFile,
diff --git a/web/packages/gallery/components/viewer/photoswipe.ts b/web/packages/gallery/components/viewer/photoswipe.ts
index 72d3fc90e3..6402a013d0 100644
--- a/web/packages/gallery/components/viewer/photoswipe.ts
+++ b/web/packages/gallery/components/viewer/photoswipe.ts
@@ -14,8 +14,8 @@ import {
fileViewerDidClose,
fileViewerWillOpen,
forgetExifForItemData,
- forgetFailedItemDataForFileID,
forgetItemDataForFileID,
+ forgetItemDataForFileIDIfNeeded,
itemDataForFile,
updateFileInfoExifIfNeeded,
type ItemData,
@@ -710,17 +710,10 @@ export class FileViewerPhotoSwipe {
const queryVideoElement = (element: HTMLElement | undefined) =>
element?.querySelector<HTMLVideoElement>("video, hls-video");
+ // PhotoSwipe invokes this event when moving away from a slide.
pswp.on("contentDeactivate", (e) => {
- // Reset failures, if any, for this file so that the fetch is tried
- // again when we come back to it^.
- //
- // ^ Note that because of how the preloading works, this will have
- // an effect (i.e. the retry will happen) only if the user moves
- // more than 2 slides and then back, or if they reopen the viewer.
- //
- // See: [Note: File viewer error handling]
const fileID = asItemData(e.content.data).fileID;
- if (fileID) forgetFailedItemDataForFileID(fileID);
+ if (fileID) forgetItemDataForFileIDIfNeeded(fileID);
// Pause the video element, if any, when we move away from the
// slide.
diff --git a/web/packages/gallery/services/video.ts b/web/packages/gallery/services/video.ts
index 511ddd6cc3..e038fb31e7 100644
--- a/web/packages/gallery/services/video.ts
+++ b/web/packages/gallery/services/video.ts
@@ -106,6 +106,21 @@ export interface HLSPlaylistData {
* any arbitrary time. So the negative result ("this file does not have a
* playlist") cannot be cached.
*
+ * So while we can easily cache the first case ("this file has a playlist"), we
+ * need to deal with the second case ("this file does not have a playlist") a
+ * bit more intricately:
+ *
+ * - If running in the context of a logged in user (e.g. photos app), we can use
+ * the "/files/data/status-diff" API to be notified of any modifications to
+ * the second case for the user's own files. This status-diff happens during
+ * the regular "sync", and we can use that as a cue to selectively prune cache
+ * entries for the second case but can otherwise indefinitely cache it.
+ *
+ * - If the file is a shared file, the status-diff will not return it. And if
+ * we're not running in the context of a logged in user (e.g. the public
+ * albums app), then there is no status-diff to do. For these two scenarios,
+ * we thus mark the cached values as "transient" and always recheck for a
+ * playlist when opening the slide.
*/
export const hlsPlaylistDataForFile = async (
file: EnteFile,