This commit is contained in:
Manav Rathi
2025-05-09 15:28:26 +05:30
parent b6173d6c1b
commit 0520fcd7ec
2 changed files with 28 additions and 3 deletions

View File

@@ -418,7 +418,7 @@ const saveSyncLastUpdatedAt = async (lastUpdatedAt: number) => {
* Fetch IDs of files from remote that have been processed by other clients
* since the last time we checked.
*/
export const syncProcessedFileIDs = async () =>
const syncProcessedFileIDs = async () =>
syncUpdatedFileDataFileIDs(
"vid_preview",
(await savedSyncLastUpdatedAt()) ?? 0,
@@ -430,6 +430,30 @@ export const syncProcessedFileIDs = async () =>
},
);
/**
* If video processing is enabled, trigger a sync with remote and any subsequent
* backfill queue processing for pending videos.
*
* This function is expected to be called during a regular sync that the app
* makes with remote (See: [Note: Remote sync]). It is a no-op if video
* processing is not enabled or eligible on this device. Otherwise it syncs the
* list of already processed file IDs with remote.
*
* At this point it also triggers a backfill (if needed), but doesn't wait for
* it to complete (which might take a time for big libraries).
*
* Calling it when a backfill has already been triggered by a previous sync is
* also a no-op. However, a backfill does not start until at least one sync of
* file IDs has been completed with remote, to avoid picking up work on file IDs
* that have already been processed elsewhere.
*/
export const videoProcessingSyncIfNeeded = async () => {
if (!isDesktop) return;
if (!isVideoProcessingEnabled()) return;
await wait(0);
};
/**
* Create a streamable HLS playlist for a video uploaded from this client.
*
@@ -457,7 +481,6 @@ export const processVideoNewUpload = (
file: EnteFile,
processableUploadItem: ProcessableUploadItem,
) => {
// TODO(HLS):
if (!isDesktop) return;
if (!isVideoProcessingEnabled()) return;
if (file.metadata.fileType !== FileType.video) return;
@@ -505,6 +528,7 @@ const tickNow = () => {
};
export const isVideoProcessingEnabled = () =>
// TODO(HLS):
process.env.NEXT_PUBLIC_ENTE_WIP_VIDEO_STREAMING &&
settingsSnapshot().isInternalUser;

View File

@@ -1,4 +1,5 @@
import { resetFileViewerDataSourceOnClose } from "ente-gallery/components/viewer/data-source";
import { videoProcessingSyncIfNeeded } from "ente-gallery/services/video";
import type { Collection } from "ente-media/collection";
import type { EnteFile } from "ente-media/file";
import { isHiddenCollection } from "ente-new/photos/services/collection";
@@ -57,7 +58,7 @@ export const preCollectionAndFilesSync = async () => {
* See: [Note: Remote sync]
*/
export const postCollectionAndFilesSync = async () => {
await Promise.all([searchDataSync()]);
await Promise.all([searchDataSync(), videoProcessingSyncIfNeeded()]);
// ML sync might take a very long time for initial indexing, so don't wait
// for it to finish.
void mlSync();