Skip to content

armgit / ente

Public Imported from GitHub
0

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

Prune stale web app migrations and accounts local-storage fallbacks

Manav Rathid939c5a1ebb8
diff --git a/web/packages/accounts-rs/services/accounts-db.ts b/web/packages/accounts-rs/services/accounts-db.ts
index f5b71e3304..4a10d2f5bf 100644
--- a/web/packages/accounts-rs/services/accounts-db.ts
+++ b/web/packages/accounts-rs/services/accounts-db.ts
@@ -170,18 +170,6 @@ export const savedLocalUser = (): LocalUser | undefined => {
return success ? data : undefined;
};
-/**
- * Sanity check to ensure that KV token and local storage token are the same.
- *
- * TODO: Added July 2025, can just be removed soon, there is already a sanity
- * check `isLocalStorageAndIndexedDBMismatch` on app start (tag: Migration).
- */
-export const ensureTokensMatch = async (user: PartialLocalUser | undefined) => {
- if (user?.token !== (await savedAuthToken())) {
- throw new Error("Token mismatch");
- }
-};
-
/**
* Return true if the saved user token in local storage and the persisted auth
* token are out of sync.
@@ -377,12 +365,6 @@ export const saveIsFirstLogin = () => {
* without clearing it by using {@link savedIsFirstLogin}.
*/
export const getAndClearIsFirstLogin = () => {
- // Completely unrelated, but since this code runs on each /gallery load, use
- // this as a chance to remove the unused "showBackButton" property saved in
- // local storage. This code was added 1.7.15-beta (July 2025) and can be
- // removed after a while, soonish (tag: Migration).
- localStorage.removeItem("showBackButton");
-
const result = savedIsFirstLogin();
localStorage.removeItem("isFirstLogin");
return result;
@@ -427,17 +409,6 @@ export const getAndClearJustSignedUp = () => {
return result;
};
-/**
- * Zod schema for the format in which the {@link stashReferralSource} used to
- * saved the referral source in local storage.
- *
- * Starting 1.7.15-beta (July 2025), we started saving the string directly, but
- * when reading we fallback to the old format if needed. This fallback can be
- * removed, and soonish, since these is a transient value that isn't expected to
- * remain in the user's local storage for long anyway. (tag: Migration).
- */
-const LocalLegacyReferralSource = z.object({ source: z.string() });
-
/**
* Save the referral source entered by the user on the signup screen in local
* storage.
@@ -455,17 +426,8 @@ export const stashReferralSource = (referralSource: string) => {
* from local storage.
*/
export const unstashReferralSource = () => {
- const jsonString = localStorage.getItem("referralSource");
- if (!jsonString) return undefined;
+ const referralSource = localStorage.getItem("referralSource");
+ if (!referralSource) return undefined;
localStorage.removeItem("referralSource");
- try {
- // Try the old format first. The trim is also a legacy expectation and
- // can be removed when we remove this fallfront.
- return LocalLegacyReferralSource.parse(
- JSON.parse(jsonString),
- ).source.trim();
- } catch {
- // Otherwise try the new format.
- return jsonString;
- }
+ return referralSource;
};
diff --git a/web/packages/accounts/services/accounts-db.ts b/web/packages/accounts/services/accounts-db.ts
index a1b6214674..c3b45965d8 100644
--- a/web/packages/accounts/services/accounts-db.ts
+++ b/web/packages/accounts/services/accounts-db.ts
@@ -121,9 +121,7 @@ const LocalUser = z.object({
export const savedPartialLocalUser = (): PartialLocalUser | undefined => {
const jsonString = localStorage.getItem("user");
if (!jsonString) return undefined;
- const result = PartialLocalUser.parse(JSON.parse(jsonString));
- void ensureTokensMatch(result);
- return result;
+ return PartialLocalUser.parse(JSON.parse(jsonString));
};
/**
@@ -169,22 +167,9 @@ export const savedLocalUser = (): LocalUser | undefined => {
if (!jsonString) return undefined;
// We might have some data, but not all of it. So do a non-throwing parse.
const { success, data } = LocalUser.safeParse(JSON.parse(jsonString));
- if (success) void ensureTokensMatch(data);
return success ? data : undefined;
};
-/**
- * Sanity check to ensure that KV token and local storage token are the same.
- *
- * TODO: Added July 2025, can just be removed soon, there is already a sanity
- * check `isLocalStorageAndIndexedDBMismatch` on app start (tag: Migration).
- */
-export const ensureTokensMatch = async (user: PartialLocalUser | undefined) => {
- if (user?.token !== (await savedAuthToken())) {
- throw new Error("Token mismatch");
- }
-};
-
/**
* Return true if the user's data is in local storage but not in IndexedDB.
*
@@ -366,12 +351,6 @@ export const saveIsFirstLogin = () => {
* without clearing it by using {@link savedIsFirstLogin}.
*/
export const getAndClearIsFirstLogin = () => {
- // Completely unrelated, but since this code runs on each /gallery load, use
- // this as a chance to remove the unused "showBackButton" property saved in
- // local storage. This code was added 1.7.15-beta (July 2025) and can be
- // removed after a while, soonish (tag: Migration).
- localStorage.removeItem("showBackButton");
-
const result = savedIsFirstLogin();
localStorage.removeItem("isFirstLogin");
return result;
@@ -416,17 +395,6 @@ export const getAndClearJustSignedUp = () => {
return result;
};
-/**
- * Zod schema for the format in which the {@link stashReferralSource} used to
- * saved the referral source in local storage.
- *
- * Starting 1.7.15-beta (July 2025), we started saving the string directly, but
- * when reading we fallback to the old format if needed. This fallback can be
- * removed, and soonish, since these is a transient value that isn't expected to
- * remain in the user's local storage for long anyway. (tag: Migration).
- */
-const LocalLegacyReferralSource = z.object({ source: z.string() });
-
/**
* Save the referral source entered by the user on the signup screen in local
* storage.
@@ -444,17 +412,8 @@ export const stashReferralSource = (referralSource: string) => {
* from local storage.
*/
export const unstashReferralSource = () => {
- const jsonString = localStorage.getItem("referralSource");
- if (!jsonString) return undefined;
+ const referralSource = localStorage.getItem("referralSource");
+ if (!referralSource) return undefined;
localStorage.removeItem("referralSource");
- try {
- // Try the old format first. The trim is also a legacy expectation and
- // can be removed when we remove this fallfront.
- return LocalLegacyReferralSource.parse(
- JSON.parse(jsonString),
- ).source.trim();
- } catch {
- // Otherwise try the new format.
- return jsonString;
- }
+ return referralSource;
};
diff --git a/web/packages/new/photos/services/migration.ts b/web/packages/new/photos/services/migration.ts
index 0526e8200c..c03038edcb 100644
--- a/web/packages/new/photos/services/migration.ts
+++ b/web/packages/new/photos/services/migration.ts
@@ -1,9 +1,5 @@
-import { isDesktop } from "ente-base/app";
-import { getKVN, removeKV, setKV } from "ente-base/kv";
+import { getKVN, setKV } from "ente-base/kv";
import log from "ente-base/log";
-import { localForage } from "ente-gallery/services/files-db";
-import { deleteDB } from "idb";
-import { retryIndexingFailuresIfNeeded } from "./ml";
/**
* App specific migrations.
@@ -30,99 +26,16 @@ import { retryIndexingFailuresIfNeeded } from "./ml";
*/
export const runMigrations = async () => {
const m = (await getKVN("migrationLevel")) ?? 0;
- const isNewInstall = m == 0;
const latest = 5;
if (m < latest) {
log.info(`Running migrations ${m} => ${latest}`);
- if (m < 1 && isDesktop) await m1();
- if (m < 2) await m2();
- if (m < 3) await m3();
- if (m < 4) m4();
- if (m < 5) m5(isNewInstall);
+ // Migration levels 1-5 (Aug 2024 - Feb 2025) were pruned.
+ // New migrations should be 6+. e.g.,
+ // if (m < 6) await m6();
await setKV("migrationLevel", latest);
}
};
-// Some of these (indicated by "Prunable") can be no-oped in the future when
-// almost all clients would've migrated over, and there wouldn't be any critical
-// impact if the few remaining outliers never ran that specific migration.
-
-// Added: Aug 2024 (v1.7.3). Prunable.
-const m1 = () =>
- Promise.all([
- // Delete the legacy face DB v1.
- deleteDB("mldata"),
-
- // Delete the legacy CLIP (mostly) related keys from LocalForage.
- localForage.removeItem("embeddings"),
- localForage.removeItem("embedding_sync_time"),
- localForage.removeItem("embeddings_v2"),
- localForage.removeItem("file_embeddings"),
- localForage.removeItem("onnx-clip-embedding_sync_time"),
- localForage.removeItem("file-ml-clip-face-embedding_sync_time"),
-
- // Delete keys for the legacy diff based sync.
- removeKV("embeddingSyncTime:onnx-clip"),
- removeKV("embeddingSyncTime:file-ml-clip-face"),
-
- // Delete the legacy face DB v2.
- deleteDB("face"),
- ]).then(() => {
- // Delete legacy ML keys.
- localStorage.removeItem("faceIndexingEnabled");
- });
-
-// Added: Sep 2024 (v1.7.5-beta). Prunable.
-const m2 = () =>
- // Older versions of the user-entities code kept the diff related state
- // in a different place. These entries are not needed anymore (the tags
- // themselves will get resynced).
- Promise.all([
- localForage.removeItem("location_tags"),
- localForage.removeItem("location_tags_key"),
- localForage.removeItem("location_tags_time"),
-
- // Remove data from an intermediate format that stored user-entities
- // piecewise instead of as generic, verbatim, entities.
- removeKV("locationTags"),
- removeKV("entityKey/locationTags"),
- removeKV("latestUpdatedAt/locationTags"),
- ]);
-
-// Added: Sep 2024 (v1.7.5-beta). Prunable.
-const m3 = () =>
- Promise.all([
- // Delete the legacy face DB v1.
- //
- // This was already removed in m1, but that was behind an isDesktop
- // check, but later I found out that old web versions also created this
- // DB (although empty).
- deleteDB("mldata"),
-
- // Remove data from an intermediate format that stored user-entities in
- // their parsed form instead of as generic, verbatim, entities.
- removeKV("locationTags"),
- removeKV("entityKey/location"),
- removeKV("latestUpdatedAt/location"),
- ]);
-
-// Added: Nov 2024 (v1.7.7-beta). Prunable.
-const m4 = () => {
- // Delete old local storage keys that have been subsumed elsewhere.
- localStorage.removeItem("mapEnabled");
- localStorage.removeItem("userDetails");
- localStorage.removeItem("subscription");
- localStorage.removeItem("familyData");
-};
-
-// Added: Feb 2025 (v1.7.10). Prunable.
-const m5 = (isNewInstall: boolean) => {
- // MUI now persists the color scheme (also in local storage). This was
- // anyway never released, was only ever an internal user flag.
- localStorage.removeItem("theme");
- if (!isNewInstall) {
- // Let the indexer have another go at the files, the new vips conversion
- // logic added since 1.7.9 might be able to convert more outliers.
- retryIndexingFailuresIfNeeded();
- }
-};
+// const m6 = () => {
+// // See git history for other examples.
+// }