This commit is contained in:
Manav Rathi
2024-12-26 17:42:41 +05:30
parent f5a3b8a3fb
commit daf3fd2a75
2 changed files with 42 additions and 3 deletions

View File

@@ -116,7 +116,7 @@ import {
getAllLatestCollections,
} from "services/collectionService";
import { syncFiles } from "services/fileService";
import { preFileInfoSync, sync } from "services/sync";
import { preCollectionsAndFilesSync, sync } from "services/sync";
import { syncTrash } from "services/trashService";
import uploadManager from "services/upload/uploadManager";
import { isTokenValid } from "services/userService";
@@ -566,7 +566,7 @@ export default function Gallery() {
throw new Error(CustomError.SESSION_EXPIRED);
}
!silent && showLoadingBar();
await preFileInfoSync();
await preCollectionsAndFilesSync();
const allCollections = await getAllLatestCollections();
const [hiddenCollections, collections] = splitByPredicate(
allCollections,

View File

@@ -1,11 +1,16 @@
import { isHiddenCollection } from "@/new/photos/services/collection";
import { isMLSupported, mlStatusSync, mlSync } from "@/new/photos/services/ml";
import { searchDataSync } from "@/new/photos/services/search";
import { syncSettings } from "@/new/photos/services/settings";
import { splitByPredicate } from "@/utils/array";
import { getAllLatestCollections } from "./collectionService";
import { syncFiles } from "./fileService";
import { syncTrash } from "./trashService";
/**
* Part 1 of {@link sync}. See TODO below for why this is split.
*/
export const preFileInfoSync = async () => {
export const preCollectionsAndFilesSync = async () => {
await Promise.all([syncSettings(), isMLSupported && mlStatusSync()]);
};
@@ -34,3 +39,37 @@ export const sync = async () => {
// for it to finish.
void mlSync();
};
/**
* Sync our local file and collection state with remote.
*
* This is a subset of {@link 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).
*
* A bespoke version of this in currently used by the gallery component when it
* syncs - it needs a broken down, bespoke version because it also keeps local
* state variables that need to be updated with the various callbacks that we
* ignore in this version.
*/
export const syncFilesAndCollections = async () => {
const allCollections = await getAllLatestCollections();
const [hiddenCollections, normalCollections] = splitByPredicate(
allCollections,
isHiddenCollection,
);
await syncFiles(
"normal",
normalCollections,
() => {},
() => {},
);
await syncFiles(
"hidden",
hiddenCollections,
() => {},
() => {},
);
await syncTrash(allCollections, () => {});
};