Skip to content

armgit / ente

Public Imported from GitHub
0

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

Split ML status sync

Manav Rathib04831d4dfcc
diff --git a/web/packages/new/photos/services/ml/index.ts b/web/packages/new/photos/services/ml/index.ts
index 1ee85c37e6..6cb54d397a 100644
--- a/web/packages/new/photos/services/ml/index.ts
+++ b/web/packages/new/photos/services/ml/index.ts
@@ -270,22 +270,40 @@ const updateIsMLEnabledRemote = (enabled: boolean) =>
updateRemoteFlag(mlRemoteKey, enabled);
/**
- * Trigger a "sync", whatever that means for the ML subsystem.
+ * Sync the ML status with remote.
*
- * This is called during the global sync sequence.
+ * This is called an at early point in the global sync sequence, without waiting
+ * for the potentially long file information sync to complete.
*
- * * It checks with remote if the ML flag is set, and updates our local flag to
- * reflect that value.
+ * It checks with remote if the ML flag is set, and updates our local flag to
+ * reflect that value.
*
- * * If ML is enabled, it pulls any missing embeddings from remote and starts
- * indexing to backfill any missing values.
+ * To trigger the actual ML sync, use {@link triggerMLSync}.
*/
-export const triggerMLSync = () => void mlSync();
+export const triggerMLStatusSync = () => void mlStatusSync();
-const mlSync = async () => {
+const mlStatusSync = async () => {
_state.isMLEnabled = await getIsMLEnabledRemote();
setIsMLEnabledLocal(_state.isMLEnabled);
triggerStatusUpdate();
+};
+
+/**
+ * Trigger a ML sync.
+ *
+ * This is called during the global sync sequence, after files information have
+ * been synced with remote.
+ *
+ * If ML is enabled, it pulls any missing embeddings from remote and starts
+ * indexing to backfill any missing values.
+ *
+ * This will only have an effect if {@link triggerMLSync} has been called at
+ * least once prior to calling this in the sync sequence.
+ */
+export const triggerMLSync = () => void mlSync();
+
+const mlSync = async () => {
+ await mlStatusSync();
if (_state.isMLEnabled) void worker().then((w) => w.sync());
};