Skip to content

armgit / ente

Public Imported from GitHub
0

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

Prep

Manav Rathieb16c925d208
diff --git a/web/apps/photos/src/services/sync.ts b/web/apps/photos/src/services/sync.ts
index ce8defd900..0e769fd6d5 100644
--- a/web/apps/photos/src/services/sync.ts
+++ b/web/apps/photos/src/services/sync.ts
@@ -4,7 +4,7 @@ import {
triggerMLStatusSync,
triggerMLSync,
} from "@/new/photos/services/ml";
-import { triggerSearchDataPrefetchIfNeeded } from "@/new/photos/services/search";
+import { triggerSearchDataSync } from "@/new/photos/services/search";
import { syncLocationTags } from "@/new/photos/services/user-entity";
import { syncEntities } from "services/entityService";
import { syncMapEnabled } from "services/userService";
@@ -42,6 +42,6 @@ export const sync = async () => {
syncLocationTags(),
syncMapEnabled(),
]);
+ triggerSearchDataSync();
if (isMLSupported) triggerMLSync();
- triggerSearchDataPrefetchIfNeeded();
};
diff --git a/web/packages/new/photos/services/search/index.ts b/web/packages/new/photos/services/search/index.ts
index de3dc0add8..6453bce3b7 100644
--- a/web/packages/new/photos/services/search/index.ts
+++ b/web/packages/new/photos/services/search/index.ts
@@ -25,13 +25,9 @@ const createComlinkWorker = () =>
);
/**
- * Preload any data that would be needed if the user were to search.
- *
- * This is an optimization to try and ensure we always have the latest state
- * by the time the user gets around to searching.
+ * Fetch any data that would be needed if the user were to search.
*/
-export const triggerSearchDataPrefetchIfNeeded = () =>
- void worker().then((w) => w.prefetchIfNeeded());
+export const triggerSearchDataSync = () => void worker().then((w) => w.sync());
/**
* Set the files over which we will search.
diff --git a/web/packages/new/photos/services/search/types.ts b/web/packages/new/photos/services/search/types.ts
index 5841899ab7..aa77e64aa1 100644
--- a/web/packages/new/photos/services/search/types.ts
+++ b/web/packages/new/photos/services/search/types.ts
@@ -83,12 +83,6 @@ export type City = Location & {
* Name of the city.
*/
name: string;
- /**
- * Name of the city, lowercased.
- *
- * Precomputing this save an lowercasing during the search itself.
- */
- lowercasedName: string;
};
export enum SuggestionType {
diff --git a/web/packages/new/photos/services/search/worker.ts b/web/packages/new/photos/services/search/worker.ts
index 031493570e..d7fee7df86 100644
--- a/web/packages/new/photos/services/search/worker.ts
+++ b/web/packages/new/photos/services/search/worker.ts
@@ -11,6 +11,11 @@ import type { Component } from "chrono-node";
import * as chrono from "chrono-node";
import { expose } from "comlink";
import { z } from "zod";
+import {
+ savedLocationTags,
+ syncLocationTags,
+ type LocationTag,
+} from "../user-entity";
import type {
City,
DateSearchResult,
@@ -22,20 +27,47 @@ import type {
} from "./types";
import { SuggestionType } from "./types";
+type SearchableCity = City & {
+ /**
+ * Name of the city, lowercased. Precomputed to save an op during search.
+ */
+ lowercasedName: string;
+};
+
+type SearchableLocationTag = LocationTag & {
+ /**
+ * Name of the location tag, lowercased. Precomputed to save an op during
+ * search.
+ */
+ lowercasedName: string;
+};
+
/**
* A web worker that runs the search asynchronously so that the main thread
* remains responsive.
*/
export class SearchWorker {
private enteFiles: EnteFile[] = [];
- private cities: City[] = [];
- private citiesPromise: Promise<void> | undefined;
+ private locationTags: SearchableLocationTag[] = [];
+ private cities: SearchableCity[] = [];
/**
- * Prefetch any data that we might need when the actual search happens.
+ * Fetch any state we might need when the actual search happens.
*/
- prefetchIfNeeded() {
- this.triggerCityFetchIfNeeded();
+ async sync() {
+ return Promise.allSettled([
+ syncLocationTags()
+ .then(() => savedLocationTags())
+ .then((ts) => {
+ this.locationTags = ts.map((t) => ({
+ ...t,
+ lowercasedName: t.name.toLowerCase(),
+ }));
+ }),
+ fetchCities().then((cs) => {
+ this.cities = cs;
+ }),
+ ]);
}
/**
@@ -53,18 +85,13 @@ export class SearchWorker {
locale: string,
holidays: DateSearchResult[],
) {
- this.prefetchIfNeeded();
- return createSearchQuery(searchString, locale, holidays, this.cities);
- }
-
- /**
- * Lazily trigger a fetch of city data, but don't wait for it to complete.
- */
- triggerCityFetchIfNeeded() {
- if (this.citiesPromise) return;
- this.citiesPromise = fetchCities().then((cs) => {
- this.cities = cs;
- });
+ return createSearchQuery(
+ searchString,
+ locale,
+ holidays,
+ this.locationTags,
+ this.cities,
+ );
}
/**
@@ -81,7 +108,8 @@ const createSearchQuery = async (
searchString: string,
locale: string,
holidays: DateSearchResult[],
- cities: City[],
+ locationTags: SearchableLocationTag[],
+ cities: SearchableCity[],
): Promise<Suggestion[]> => {
// Normalize it by trimming whitespace and converting to lowercase.
const s = searchString.trim().toLowerCase();
diff --git a/web/packages/new/photos/services/user-entity.ts b/web/packages/new/photos/services/user-entity.ts
index 1a040595df..9a2af8680d 100644
--- a/web/packages/new/photos/services/user-entity.ts
+++ b/web/packages/new/photos/services/user-entity.ts
@@ -61,8 +61,6 @@ export const syncLocationTags = async () => {
return saveLocationTags([...existingTagsByID.values()]);
};
- // TODO-cgroup: Call me
- // await removeLegacyDBState();
return syncUserEntity("location", processBatch);
};