Skip to content

Commit

Permalink
[desktop] Shared indexes (#4633)
Browse files Browse the repository at this point in the history
Sibling of #4569
  • Loading branch information
mnvr authored Jan 8, 2025
2 parents 8656f69 + ac3fbf8 commit 61b42a0
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 35 deletions.
7 changes: 3 additions & 4 deletions web/packages/base/locales/en-US/translation.json
Original file line number Diff line number Diff line change
Expand Up @@ -223,10 +223,9 @@
"terms_and_conditions": "I agree to the <a>terms</a> and <b>privacy policy</b>",
"people": "People",
"indexing_scheduled": "Indexing is scheduled...",
"indexing_photos": "Indexing photos ({{nSyncedFiles, number}} / {{nTotalFiles, number}})",
"indexing_fetching": "Fetching indexes ({{nSyncedFiles, number}} / {{nTotalFiles, number}})",
"indexing_people": "Indexing people in {{nSyncedFiles, number}} photos...",
"indexing_done": "Indexed {{nSyncedFiles, number}} photos",
"indexing_photos": "Updating indexes...",
"indexing_fetching": "Syncing indexes...",
"indexing_people": "Syncing people...",
"syncing_wait": "Syncing...",
"people_empty_too_few": "People will be shown here when there are sufficient photos of a person",
"unnamed_person": "Unnamed person",
Expand Down
14 changes: 6 additions & 8 deletions web/packages/new/photos/components/SearchBar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -375,7 +375,8 @@ const shouldShowEmptyState = (inputValue: string) => {
if (!isMLSupported) return false;

const status = mlStatusSnapshot();
if (!status || status.phase == "disabled") return false;
if (!status || status.phase == "disabled" || status.phase == "done")
return false;

// Show it otherwise.
return true;
Expand All @@ -391,7 +392,7 @@ const EmptyState: React.FC<
const mlStatus = useMLStatusSnapshot();
const people = usePeopleStateSnapshot()?.visiblePeople;

if (!mlStatus || mlStatus.phase == "disabled") {
if (!mlStatus || mlStatus.phase == "disabled" || mlStatus.phase == "done") {
// The preflight check should've prevented us from coming here.
assertionFailed();
return <></>;
Expand All @@ -403,16 +404,13 @@ const EmptyState: React.FC<
label = t("indexing_scheduled");
break;
case "indexing":
label = t("indexing_photos", mlStatus);
label = t("indexing_photos");
break;
case "fetching":
label = t("indexing_fetching", mlStatus);
label = t("indexing_fetching");
break;
case "clustering":
label = t("indexing_people", mlStatus);
break;
case "done":
label = t("indexing_done", mlStatus);
label = t("indexing_people");
break;
}

Expand Down
8 changes: 2 additions & 6 deletions web/packages/new/photos/components/sidebar/MLSettings.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -264,12 +264,8 @@ const ManageML: React.FC<ManageMLProps> = ({ mlStatus, onDisableML }) => {
break;
}

// When clustering, show the progress as a percentage instead of the
// potentially confusing total counts during incremental updates.
const processed =
phase == "clustering"
? `${Math.round((100 * nSyncedFiles) / nTotalFiles)}%`
: `${nSyncedFiles} / ${nTotalFiles}`;
// Show processed as percentages instead of potentially confusing counts.
const processed = `${Math.round((100 * nSyncedFiles) / nTotalFiles)}%`;

const confirmDisableML = () =>
showMiniDialog({
Expand Down
4 changes: 1 addition & 3 deletions web/packages/new/photos/services/ml/db.ts
Original file line number Diff line number Diff line change
Expand Up @@ -249,9 +249,7 @@ export const addFileEntry = async (fileID: number) => {
/**
* Update entries in ML DB to align with the state of local files outside ML DB.
*
* @param localFileIDs IDs of all the files that the client is aware of,
* filtered to only keep the files that the user owns and the formats that can
* be indexed by our current indexing pipelines.
* @param localFileIDs IDs of all the files that the client is aware of.
*
* @param localTrashFilesIDs IDs of all the files in trash.
*
Expand Down
16 changes: 2 additions & 14 deletions web/packages/new/photos/services/ml/worker.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { clientPackageName } from "@/base/app";
import { assertionFailed } from "@/base/assert";
import { isHTTP4xxError } from "@/base/http";
import { getKVN } from "@/base/kv";
import log from "@/base/log";
import type { ElectronMLWorker } from "@/base/types/ipc";
import { fileLogID, type EnteFile } from "@/media/file";
Expand Down Expand Up @@ -286,12 +285,8 @@ export class MLWorker {

/** Return the next batch of items to backfill (if any). */
private async backfillQ() {
const userID = (await getKVN("userID"))!;
// Find files that our local DB thinks need syncing.
const fileByID = await syncWithLocalFilesAndGetFilesToIndex(
userID,
200,
);
const fileByID = await syncWithLocalFilesAndGetFilesToIndex(200);
if (!fileByID.size) return [];

// Fetch their existing ML data (if any).
Expand Down Expand Up @@ -429,20 +424,13 @@ const indexNextBatch = async (
*
* For specifics of what a "sync" entails, see {@link updateAssumingLocalFiles}.
*
* @param userID Sync only files owned by a {@link userID} with the face DB.
*
* @param count Limit the resulting list of indexable files to {@link count}.
*/
const syncWithLocalFilesAndGetFilesToIndex = async (
userID: number,
count: number,
): Promise<Map<number, EnteFile>> => {
const isIndexable = (f: EnteFile) => f.ownerID == userID;

const localFiles = await getAllLocalFiles();
const localFileByID = new Map(
localFiles.filter(isIndexable).map((f) => [f.id, f]),
);
const localFileByID = new Map(localFiles.map((f) => [f.id, f]));

const localTrashFileIDs = (await getLocalTrashedFiles()).map((f) => f.id);

Expand Down

0 comments on commit 61b42a0

Please sign in to comment.