Skip to content

armgit / ente

Public Imported from GitHub
0

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

Post rename - 1

Manav Rathi4161371a8eeb
diff --git a/web/apps/photos/src/pages/gallery.tsx b/web/apps/photos/src/pages/gallery.tsx
index c0563fee08..74b14eb0b4 100644
--- a/web/apps/photos/src/pages/gallery.tsx
+++ b/web/apps/photos/src/pages/gallery.tsx
@@ -78,17 +78,17 @@ import {
savedCollections,
savedTrashItems,
} from "ente-new/photos/services/photos-fdb";
+import {
+ pullFiles,
+ pullFilesPost,
+ pullFilesPre,
+} from "ente-new/photos/services/pull";
import {
filterSearchableFiles,
updateSearchCollectionsAndFiles,
} from "ente-new/photos/services/search";
import type { SearchOption } from "ente-new/photos/services/search/types";
import { initSettings } from "ente-new/photos/services/settings";
-import {
- postCollectionAndFilesSync,
- preCollectionAndFilesSync,
- syncCollectionAndFiles,
-} from "ente-new/photos/services/sync";
import {
initUserDetailsOrTriggerSync,
redirectToCustomerPortal,
@@ -505,14 +505,13 @@ const Page: React.FC = () => {
}, [showLoadingBar, hideLoadingBar]);
/**
- * Sync the local files and collection with remote.
+ * Pull latest collections, collection files and trash items from remote.
*
- * [Note: Full sync vs file and collection sync]
+ * [Note: Full remote pull vs files pull]
*
- * This is a subset of the sync which happens in {@link syncWithRemote}, but
- * in some cases where we know that the changes will not have transitive
- * effects outside of the locally stored files and collections this is a
- * better option for interactive operations because:
+ * If we know that our operation will not have other transitive effects
+ * beyond collections, collection files and trash, this is a better option
+ * as compared to a full remote pull for interactive operations because:
*
* 1. This involves a lesser number of API requests, so it reduces the time
* the user has to wait for their interactive request to complete.
@@ -522,7 +521,7 @@ const Page: React.FC = () => {
* invocation of {@link fileAndCollectionSyncWithRemote} is independent.
*/
const fileAndCollectionSyncWithRemote = useCallback(async () => {
- const didUpdateFiles = await syncCollectionAndFiles({
+ const didUpdateFiles = await pullFiles({
onSetCollections: (collections) =>
dispatch({ type: "setCollections", collections }),
onSetCollectionFiles: (collectionFiles) =>
@@ -568,7 +567,7 @@ const Page: React.FC = () => {
isSyncing.current = true;
try {
if (!silent) showLoadingBar();
- await preCollectionAndFilesSync();
+ await pullFilesPre();
await fileAndCollectionSyncWithRemote();
// syncWithRemote is called with the force flag set to true before
// doing an upload. So it is possible, say when resuming a pending
@@ -576,7 +575,7 @@ const Page: React.FC = () => {
//
// Do the non-file-related sync only for one of these parallel ones.
if (!isForced) {
- await postCollectionAndFilesSync();
+ await pullFilesPost();
}
} catch (e) {
log.error("syncWithRemote failed", e);
diff --git a/web/packages/accounts/services/session.ts b/web/packages/accounts/services/session.ts
index 05e4c64d97..b10967f02d 100644
--- a/web/packages/accounts/services/session.ts
+++ b/web/packages/accounts/services/session.ts
@@ -130,7 +130,7 @@ export const checkSessionValidity = async (): Promise<SessionValidity> => {
* longer valid. If needed, also update the key attributes at remote.
*
* This is a subset of {@link checkSessionValidity} that has been tailored for
- * use during each remote sync, to detect if the user has been logged out
+ * use during each remote pull, to detect if the user has been logged out
* elsewhere.
*
* @returns `true` if either we don't have an auth token, or if remote tells us
diff --git a/web/packages/gallery/services/video.ts b/web/packages/gallery/services/video.ts
index 2e13cc350b..68a4644295 100644
--- a/web/packages/gallery/services/video.ts
+++ b/web/packages/gallery/services/video.ts
@@ -617,7 +617,7 @@ const saveSyncLastUpdatedAt = (lastUpdatedAt: number) =>
* Fetch IDs of files from remote that have been processed by other clients
* since the last time we checked.
*/
-const syncProcessedFileIDs = async () =>
+const pullProcessedFileIDs = async () =>
syncUpdatedFileDataFileIDs(
"vid_preview",
(await savedSyncLastUpdatedAt()) ?? 0,
@@ -657,19 +657,19 @@ export const videoPrunePermanentlyDeletedFileIDsIfNeeded = async (
};
/**
- * If video processing is enabled, trigger a sync with remote and any subsequent
- * backfill queue processing for pending videos.
+ * If video processing is enabled, trigger a pull from remote and then proceed
+ * with any subsequent backfill queue processing of 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.
+ * This function is intended to be called during a full remote pull (See: [Note:
+ * Remote pull]). It is a no-op if video processing is not enabled or eligible
+ * on this device. Otherwise it pulls 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).
+ * At this point it also triggers processing of the 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
+ * also a no-op. However, a backfill does not start until at least one pull of
* file IDs has been completed with remote, to avoid picking up work on file IDs
* that have already been processed elsewhere.
*/
@@ -685,7 +685,7 @@ export const videoProcessingSyncIfNeeded = async () => {
if (!isHLSGenerationEnabled()) return;
- await syncProcessedFileIDs();
+ await pullProcessedFileIDs();
tickNow(); /* if not already ticking */
};
diff --git a/web/packages/new/photos/services/dedup.ts b/web/packages/new/photos/services/dedup.ts
index 158f02a420..ca549e6571 100644
--- a/web/packages/new/photos/services/dedup.ts
+++ b/web/packages/new/photos/services/dedup.ts
@@ -10,7 +10,7 @@ import {
savedNormalCollections,
} from "./collection";
import { savedCollectionFiles } from "./photos-fdb";
-import { syncCollectionAndFiles } from "./pull";
+import { pullFiles } from "./pull";
/**
* A group of duplicates as shown in the UI.
@@ -290,7 +290,7 @@ export const removeSelectedDuplicateGroups = async (
}
// Sync our local state.
- await syncCollectionAndFiles();
+ await pullFiles();
tickProgress();
return new Set(selectedDuplicateGroups.map((g) => g.id));
diff --git a/web/packages/new/photos/services/ml/index.ts b/web/packages/new/photos/services/ml/index.ts
index c299a088a7..3ec6c44e26 100644
--- a/web/packages/new/photos/services/ml/index.ts
+++ b/web/packages/new/photos/services/ml/index.ts
@@ -304,7 +304,7 @@ export const retryIndexingFailuresIfNeeded = () => {
};
/**
- * Sync the ML status with remote.
+ * Update our local ML status with the latest value from remote.
*
* This is called an at early point in the global sync sequence, without waiting
* for the potentially long file information sync to complete.
@@ -312,9 +312,9 @@ export const retryIndexingFailuresIfNeeded = () => {
* It checks with remote if the ML flag is set, and updates our local flag to
* reflect that value.
*
- * To perform the actual ML sync, use {@link mlSync}.
+ * To perform the actual ML data pull, use {@link mlSync}.
*/
-export const mlStatusSync = async () => {
+export const pullMLStatus = async () => {
_state.isMLEnabled = await getIsMLEnabledRemote();
setIsMLEnabledLocal(_state.isMLEnabled);
return updateMLStatusSnapshot();
@@ -323,16 +323,16 @@ export const mlStatusSync = async () => {
/**
* Perform a ML sync, whatever is applicable.
*
- * This is called during the global sync sequence, after files information have
- * been synced with remote.
+ * This is called during the global pull sequence, after files information have
+ * been pulled with remote.
*
* If ML is enabled, it pulls any missing embeddings from remote and starts
- * indexing to backfill any missing values. It also syncs cgroups and updates
+ * indexing to backfill any missing values. It also pulls cgroups and updates
* the search service to use the latest values. Finally, it uses the latest
* files, faces and cgroups to update the people shown in the UI.
*
- * This will only have an effect if {@link mlStatusSync} has been called at
- * least once prior to calling this in the sync sequence.
+ * This will only have an effect if {@link pullMLStatus} has been called at
+ * least once prior to calling this in the pull sequence.
*/
export const mlSync = async () => {
if (!_state.isMLEnabled) return;
diff --git a/web/packages/new/photos/services/pull.ts b/web/packages/new/photos/services/pull.ts
index f4d2aeda0e..5459b7117a 100644
--- a/web/packages/new/photos/services/pull.ts
+++ b/web/packages/new/photos/services/pull.ts
@@ -7,56 +7,43 @@ import type { Collection } from "ente-media/collection";
import type { EnteFile } from "ente-media/file";
import { pullCollections } from "./collection";
import { pullCollectionFiles } from "./files";
-import { isMLSupported, mlStatusSync, mlSync } from "./ml";
+import { isMLSupported, mlSync, pullMLStatus } from "./ml";
import { searchDataSync } from "./search";
-import { syncSettings } from "./settings";
+import { pullSettings } from "./settings";
import { pullTrash, type TrashItem } from "./trash";
/**
- * Called during a full sync, before doing the collection and file sync.
+ * Called during a full remote pull, before doing the files pull.
*
- * [Note: Remote sync]
+ * [Note: Remote pull]
*
- * There are two types of remote syncs we perform:
+ * There are two types of remote pulls we perform:
*
- * - A "collection and file" sync: Syncing our local state of collections and
- * files with remote.
+ * - A "files" pull: Updating our local state with the latest collections,
+ * collection files, and trash from remote.
*
- * - A "full" sync, which includes the collection and file sync, and more.
+ * - A "full" pull, which includes the files pull, and more.
*
- * The full sync is performed by the gallery page, in the following sequence:
+ * The full pull is performed by the gallery page, in the following sequence:
*
- * 1. {@link preCollectionAndFilesSync}
- * 2. {@link syncCollectionAndFiles}
- * 3. {@link postCollectionAndFilesSync}.
+ * 1. {@link pullFilesPre}
+ * 2. {@link pullFiles}
+ * 3. {@link pullFilesPost}.
*
- * In some other cases, where we know that only specific collection and/or file
- * state needs to be synced, step 2 ({@link syncCollectionAndFiles}) is
- * performed independently. The only example of such a cases currently is:
- *
- * - After deduping files.
- *
- * The full sync is performed in the following cases:
+ * The full pull is performed in the following cases:
*
* - On the gallery page load (for both web and desktop).
* - Every 5 minutes thereafter (while the user is on the gallery page).
* - Each time the desktop app gains focus.
* - When the file viewer is closed after performing some operation.
- */
-export const preCollectionAndFilesSync = async () => {
- await Promise.all([syncSettings(), isMLSupported && mlStatusSync()]);
-};
-
-/**
- * Called during a full sync, after doing the collection and file sync.
*
- * See: [Note: Remote sync]
+ * In some other cases, where we know that only specific collection or file
+ * state needs to be pulled, step 2 ({@link pullFiles}) is performed
+ * independently. For example, after deduping files, or updating the metadata of
+ * a file. See also: [Note: Full remote pull vs files pull]
*/
-export const postCollectionAndFilesSync = async () => {
- 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();
+export const pullFilesPre = async () => {
+ await Promise.all([pullSettings(), isMLSupported && pullMLStatus()]);
};
interface PullFilesOpts {
@@ -83,22 +70,22 @@ interface PullFilesOpts {
}
/**
- * Sync our local file and collection state with remote.
+ * Pull the latest collections, collections files and trash items from remote.
*
- * This is a subset of a full sync, independently exposed for use at times when
- * we only want to sync collections and files (e.g. we just made some API
- * request that modified collections or files, and so now want to sync our local
- * changes to match remote).
+ * This is a subset of a full remote pull, independently exposed for use at
+ * times when we only want to pull the file related information (e.g. we just
+ * made some API request that modified collections or files, and so now want to
+ * sync our local changes to match remote).
*
- * See: [Note: Remote sync]
+ * See also: [Note: Remote pull]
*
* @param opts various callbacks that are used by gallery to update its local
- * state in tandem with the sync. The callbacks are optional since we might not
+ * state in tandem with the pull. The callbacks are optional since we might not
* have local state to update, as is the case when this is invoked post dedup.
*
* @returns `true` if one or more files were updated during the pull.
*/
-export const syncCollectionAndFiles = async (opts?: PullFilesOpts) => {
+export const pullFiles = async (opts?: PullFilesOpts) => {
const collections = await pullCollections();
opts?.onSetCollections(collections);
const didUpdateFiles = await pullCollectionFiles(
@@ -123,3 +110,15 @@ export const syncCollectionAndFiles = async (opts?: PullFilesOpts) => {
}
return false;
};
+
+/**
+ * Called during a full remote pull, after doing the files pull.
+ *
+ * See: [Note: Remote pull]
+ */
+export const pullFilesPost = async () => {
+ 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();
+};
diff --git a/web/packages/new/photos/services/settings.ts b/web/packages/new/photos/services/settings.ts
index fadea19a42..d5ae3bf14d 100644
--- a/web/packages/new/photos/services/settings.ts
+++ b/web/packages/new/photos/services/settings.ts
@@ -22,12 +22,12 @@ import { fetchFeatureFlags, updateRemoteFlag } from "./remote-store";
* 1. On app start, the initial are read from local storage in
* {@link initSettings}.
*
- * 2. During the remote sync, remote flags are fetched and saved in local
+ * 2. During the remote pull, remote flags are fetched and saved in local
* storage, and the in-memory state updated to reflect the latest values
- * ({@link syncSettings}).
+ * ({@link pullSettings}).
*
* 3. Updating a value also cause an unconditional fetch and update
- * ({@link syncSettings}).
+ * ({@link pullSettings}).
*
* 4. The individual getter functions for the flags (e.g.
* {@link isInternalUser}) return the in-memory values, and so are suitable
@@ -120,7 +120,7 @@ export const logoutSettings = () => {
* Fetch remote flags from remote and save them in local storage for subsequent
* lookup. Then use the results to update our in memory state if needed.
*/
-export const syncSettings = async () => {
+export const pullSettings = async () => {
const jsonString = await fetchFeatureFlags().then((res) => res.text());
// Do a parse as a sanity check before saving the string contents.
FeatureFlags.parse(JSON.parse(jsonString));
@@ -205,7 +205,7 @@ const isDevUserViaEmail = () => {
*/
export const updateMapEnabled = async (isEnabled: boolean) => {
await updateRemoteFlag("mapEnabled", isEnabled);
- return syncSettings();
+ return pullSettings();
};
const cfProxyDisabledKey = "cfProxyDisabled";