Skip to content

armgit / ente

Public Imported from GitHub
0

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

Clear transient

Manav Rathi7d92b5923b6b
diff --git a/web/packages/gallery/components/viewer/data-source.ts b/web/packages/gallery/components/viewer/data-source.ts
index 9c57213049..125a47686f 100644
--- a/web/packages/gallery/components/viewer/data-source.ts
+++ b/web/packages/gallery/components/viewer/data-source.ts
@@ -145,6 +145,11 @@ export type ItemData = PhotoSwipeSlideData & {
* original file could not be fetched because of an network error).
*/
fetchFailed?: boolean;
+ /**
+ * This will be `true` if the item data for this particular file is
+ * considered transient, and should not be cached.
+ */
+ isTransient?: boolean;
};
/**
@@ -364,12 +369,33 @@ export const forgetItemDataForFileID = (fileID: number) => {
* we can reset failures, if any, for a slide so that the fetch is tried again
* when we come back to it.
*
+ * [Note: File viewer preloading and contentDeactivate]
+ *
+ * Note that because of preloading, this will only have a user visible effect if
+ * the user moves out of the preload range. Let's take an example:
+ *
+ * - User opens slide at index `i`. Then the adjacent slides, `i - 1` and `i +
+ * 1`, also get preloaded.
+ *
+ * - User moves away from `i` (in either direction, but let us take the example
+ * if they move `i - 1`).
+ *
+ * - This function will get called for `i` and will clear any failed or
+ * transient state.
+ *
+ * - But since PhotoSwipe already has the slides ready for `i`, if the user then
+ * moves back to `i` then PhotoSwipe will not attempt to recreate the slide
+ * and so will not even try to get "itemData". So this will only have an
+ * effect if they move out of preload range (e.g. `i - 1`, `i - 2`), and then
+ * back (`i - 1`, `i`).
+ *
* See: [Note: File viewer error handling]
*
* See: [Note: Caching HLS playlist data]
*/
export const forgetItemDataForFileIDIfNeeded = (fileID: number) => {
- if (_state.itemDataByFileID.get(fileID)?.fetchFailed)
+ const itemData = _state.itemDataByFileID.get(fileID);
+ if (itemData?.fetchFailed || itemData?.isTransient)
forgetItemDataForFileID(fileID);
};
@@ -441,7 +467,22 @@ const enqueueUpdates = async (
createHLSPlaylistItemDataValidity(),
);
} else {
- update(videoURLD);
+ if (shouldUsePlayerV2()) {
+ // See: [Note: Caching HLS playlist data]
+ //
+ // TODO(HLS): As an optimization, we can handle the logged in vs
+ // public albums case separately once we have the status-diff
+ // state, we don't need to mark status-diff case as transient.
+ //
+ // Note that setting the transient flag is not too expensive,
+ // since the underlying videoURL is still cached by the download
+ // manager. So effectively, under normal circumstance, it just
+ // adds one API call (to recheck if an HLS playlist now exists
+ // for the given file).
+ update({ ...videoURLD, isTransient: true });
+ } else {
+ update(videoURLD);
+ }
}
};
diff --git a/web/packages/gallery/components/viewer/photoswipe.ts b/web/packages/gallery/components/viewer/photoswipe.ts
index 6402a013d0..c2caee211e 100644
--- a/web/packages/gallery/components/viewer/photoswipe.ts
+++ b/web/packages/gallery/components/viewer/photoswipe.ts
@@ -710,8 +710,12 @@ 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) => {
+ // PhotoSwipe invokes this event when moving away from a slide.
+ //
+ // However it might not have an effect until we move out of preload
+ // range. See: [Note: File viewer preloading and contentDeactivate].
+
const fileID = asItemData(e.content.data).fileID;
if (fileID) forgetItemDataForFileIDIfNeeded(fileID);
diff --git a/web/packages/gallery/services/video.ts b/web/packages/gallery/services/video.ts
index e038fb31e7..ec1cb4d419 100644
--- a/web/packages/gallery/services/video.ts
+++ b/web/packages/gallery/services/video.ts
@@ -93,12 +93,11 @@ export interface HLSPlaylistData {
*
* - If a file has a corresponding HLS playlist, then currently there is no
* scenario (apart from file deletion, where the playlist also gets deleted)
- * where the playlist is updated or deleted after being created. There is
- * still going to be a limit to the validity of the presigned chunk URLs
- * within the playlist we create which we do handle (see
- * `createHLSPlaylistItemDataValidity`), but the original playlist itself does
- * not change. In particular, a positive result ("this file has a playlist")
- * can be cached indefinitely.
+ * where the playlist is updated or deleted after being created. There is a
+ * limit to the validity of the presigned chunk URLs within the playlist we
+ * create which we do handle (`createHLSPlaylistItemDataValidity`), but the
+ * original playlist itself does not change. In particular, a positive result
+ * ("this file has a playlist") can be cached indefinitely.
*
* - If a file does not have a HLS playlist, and it is eligible for being
* streamed (e.g. it is not too small where the streaming overhead is not
@@ -114,7 +113,7 @@ export interface HLSPlaylistData {
* 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.
+ * 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