Skip to content

armgit / ente

Public Imported from GitHub
0

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

skip case

Manav Rathie541f0522d93
diff --git a/web/packages/gallery/components/viewer/data-source.ts b/web/packages/gallery/components/viewer/data-source.ts
index 6c5d4a3727..8eccce3179 100644
--- a/web/packages/gallery/components/viewer/data-source.ts
+++ b/web/packages/gallery/components/viewer/data-source.ts
@@ -4,7 +4,7 @@ import { downloadManager } from "ente-gallery/services/download";
import { extractRawExif, parseExif } from "ente-gallery/services/exif";
import {
hlsPlaylistDataForFile,
- type HLSPlaylistData,
+ type HLSPlaylistDataForFile,
} from "ente-gallery/services/video";
import type { EnteFile } from "ente-media/file";
import { fileCaption, filePublicMagicMetadata } from "ente-media/file-metadata";
@@ -452,10 +452,14 @@ const enqueueUpdates = async (
const updateVideo = (
videoURL: string | undefined,
- hlsPlaylistData: HLSPlaylistData | undefined,
+ hlsPlaylistData: HLSPlaylistDataForFile,
) => {
const videoURLD = videoURL ? { videoURL } : {};
- if (hlsPlaylistData) {
+ // See: [Note: Caching HLS playlist data]
+ //
+ // In brief, there are three cases:
+ if (typeof hlsPlaylistData == "object") {
+ // 1. If we have a playlist, we can cache it
const {
playlistURL: videoPlaylistURL,
width,
@@ -466,18 +470,9 @@ const enqueueUpdates = async (
createHLSPlaylistItemDataValidity(),
);
} else {
- // 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 });
+ // 2. if the file is not eligible ("skip"), we can cache it.
+ // 3. Otherwise we shouldn't cache it indefinitely.
+ update({ ...videoURLD, isTransient: hlsPlaylistData != "skip" });
}
};
@@ -526,7 +521,7 @@ const enqueueUpdates = async (
}
try {
- let hlsPlaylistData: HLSPlaylistData | undefined;
+ let hlsPlaylistData: HLSPlaylistDataForFile;
if (file.metadata.fileType == FileType.video) {
hlsPlaylistData = await hlsPlaylistDataForFile(
file,
@@ -534,7 +529,10 @@ const enqueueUpdates = async (
);
// We have a HLS playlist, and the user didn't request the original.
// Early return so that we don't initiate a fetch for the original.
- if (hlsPlaylistData && opts?.videoQuality != "original") {
+ if (
+ typeof hlsPlaylistData == "object" &&
+ opts?.videoQuality != "original"
+ ) {
updateVideo(undefined, hlsPlaylistData);
return;
}
diff --git a/web/packages/gallery/services/video.ts b/web/packages/gallery/services/video.ts
index b0c2b75f80..06364d42fa 100644
--- a/web/packages/gallery/services/video.ts
+++ b/web/packages/gallery/services/video.ts
@@ -290,6 +290,11 @@ export interface HLSPlaylistData {
height: number;
}
+/**
+ * See: [Note: Caching HLS playlist data] for the semantics of "skip".
+ */
+export type HLSPlaylistDataForFile = HLSPlaylistData | "skip" | undefined;
+
/**
* Return a HLS playlist that can be used to stream playback of then given video
* {@link file}.
@@ -323,34 +328,35 @@ export interface HLSPlaylistData {
* regenerated again). All in all, this means that 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
- * required), then a client (this one, or a different one) can process it at
- * 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 a file does not have a HLS playlist, it might be because it is not
+ * eligible for being streamed (e.g. it is already small and in a compatible
+ * codec). See [Note: Marking files which do not need video processing] for
+ * more details of this case. In particular, we can cache this state in memory
+ * indefinitely too, since there isn't a current case where either this
+ * eligibility can change, or the client gain the ability to handle them
+ * without restarting.
*
- * - 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).
+ * - Finally, if a file does not have an HLS playlist but and it is eligible for
+ * being streamed, then a client (this one, or a different one) can process it
+ * at any arbitrary time. So the negative result ("this file does not have a
+ * playlist") cannot be cached.
*
- * - 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.
+ * So while we can easily cache the first case ("this file has a playlist") and
+ * second case ("this file doesn't need a streaming variant"), we need to deal
+ * with the third case ("this file does not have a playlist") by marking the
+ * cached values as "transient" and always recheck for a playlist when opening
+ * the slide.
*/
export const hlsPlaylistDataForFile = async (
file: EnteFile,
publicAlbumsCredentials?: PublicAlbumsCredentials,
-): Promise<HLSPlaylistData | undefined> => {
+): Promise<HLSPlaylistDataForFile> => {
ensurePrecondition(file.metadata.fileType == FileType.video);
+ if (filePublicMagicMetadata(file)?.sv == 1) {
+ return "skip";
+ }
+
const playlistFileData = await fetchFileData(
"vid_preview",
file.id,