Skip to content

armgit / ente

Public Imported from GitHub
0

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

Replace

Manav Rathid33ba285a6f3
diff --git a/web/docs/dependencies.md b/web/docs/dependencies.md
index 74e0076daf..280da4aea8 100644
--- a/web/docs/dependencies.md
+++ b/web/docs/dependencies.md
@@ -172,9 +172,7 @@ For more details, see [translations.md](translations.md).
layer on top of web workers to make them more easier to use.
- [idb](https://github.com/jakearchibald/idb) provides a promise API over the
- browser-native IndexedDB APIs, and is used as our primary tabular database.
- [idb-keyval](https://github.com/jakearchibald/idb-keyval) is its sibling
- library that we use for ad-hoc key value storage.
+ browser-native IndexedDB APIs.
> For more details about IDB and its role, see [storage.md](storage.md).
diff --git a/web/docs/storage.md b/web/docs/storage.md
index 729c6fd663..8be709f222 100644
--- a/web/docs/storage.md
+++ b/web/docs/storage.md
@@ -28,7 +28,8 @@ IndexedDB is a transactional NoSQL store provided by browsers. It has quite
large storage limits, and data is stored per origin (and remains persistent
across tab restarts).
-Unlike local storage, IndexedDB is also accessible from web workers.
+Unlike local storage, IndexedDB is also accessible from web workers and so we
+also use IndexedDB for storing ad-hoc key value pairs.
Older code used the LocalForage library for storing things in Indexed DB. This
library falls back to localStorage in case Indexed DB storage is not available.
@@ -41,13 +42,6 @@ For more details, see:
- https://web.dev/articles/indexeddb
- https://github.com/jakearchibald/idb
-## IndexedDB KV
-
-We earlier used local storage for ad-hoc key value storage, but local storage is
-not accessible from web workers which we use quite a bit. So now we use _idb_'s
-sibling libary, idb-keyval, for storing key value pairs that need to be accessed
-from both the main thread and web workers.
-
## OPFS
OPFS is used for caching entire files when we're running under Electron (the Web
diff --git a/web/packages/accounts/services/logout.ts b/web/packages/accounts/services/logout.ts
index 3e9beeeb15..079366524e 100644
--- a/web/packages/accounts/services/logout.ts
+++ b/web/packages/accounts/services/logout.ts
@@ -1,11 +1,11 @@
import { clearBlobCaches } from "@/next/blob-cache";
import { clearHTTPState } from "@/next/http";
+import { clearKVDB } from "@/next/kv";
import log from "@/next/log";
import InMemoryStore from "@ente/shared/storage/InMemoryStore";
import localForage from "@ente/shared/storage/localForage";
import { clearData } from "@ente/shared/storage/localStorage";
import { clearKeys } from "@ente/shared/storage/sessionStorage";
-import { clear as clearKV } from "idb-keyval";
import { logout as remoteLogout } from "../api/user";
/**
@@ -25,41 +25,41 @@ export const accountLogout = async () => {
try {
await remoteLogout();
} catch (e) {
- ignoreError("remote", e);
+ ignoreError("Remote", e);
}
try {
InMemoryStore.clear();
} catch (e) {
- ignoreError("in-memory store", e);
+ ignoreError("In-memory store", e);
}
try {
clearKeys();
} catch (e) {
- ignoreError("session store", e);
+ ignoreError("Session storage", e);
}
try {
clearData();
} catch (e) {
- ignoreError("local storage", e);
+ ignoreError("Local storage", e);
}
try {
await localForage.clear();
} catch (e) {
- ignoreError("local forage", e);
+ ignoreError("Local forage", e);
}
try {
await clearBlobCaches();
} catch (e) {
- ignoreError("cache", e);
+ ignoreError("Blob cache", e);
}
try {
clearHTTPState();
} catch (e) {
- ignoreError("http", e);
+ ignoreError("HTTP", e);
}
try {
- await clearKV();
+ await clearKVDB();
} catch (e) {
- ignoreError("kv", e);
+ ignoreError("KV DB", e);
}
};
diff --git a/web/packages/new/photos/components/DevSettings.tsx b/web/packages/new/photos/components/DevSettings.tsx
index e8a4f197fb..62408f4d81 100644
--- a/web/packages/new/photos/components/DevSettings.tsx
+++ b/web/packages/new/photos/components/DevSettings.tsx
@@ -1,3 +1,4 @@
+import { getKV, removeKV, setKV } from "@/next/kv";
import log from "@/next/log";
import InfoOutlinedIcon from "@mui/icons-material/InfoOutlined";
import {
@@ -14,7 +15,6 @@ import {
} from "@mui/material";
import { useFormik } from "formik";
import { t } from "i18next";
-import { del, get, set } from "idb-keyval";
import React, { useEffect, useState } from "react";
import { z } from "zod";
import { FocusVisibleButton } from "./FocusVisibleButton";
@@ -68,7 +68,7 @@ const Contents: React.FC<ContentsProps> = (props) => {
useEffect(
() =>
- void get<string>("apiOrigin").then((o) =>
+ void getKV("apiOrigin").then((o) =>
setInitialAPIOrigin(
// TODO: Migration of apiOrigin from local storage to indexed DB
// Remove me after a bit (27 June 2024).
@@ -213,7 +213,7 @@ const Form: React.FC<FormProps> = ({ initialAPIOrigin, onClose }) => {
*/
const updateAPIOrigin = async (origin: string) => {
if (!origin) {
- await del("apiOrigin");
+ await removeKV("apiOrigin");
// TODO: Migration of apiOrigin from local storage to indexed DB
// Remove me after a bit (27 June 2024).
localStorage.removeItem("apiOrigin");
@@ -230,7 +230,7 @@ const updateAPIOrigin = async (origin: string) => {
throw new Error("Invalid response");
}
- await set("apiOrigin", origin);
+ await setKV("apiOrigin", origin);
};
const PingResponse = z.object({
diff --git a/web/packages/next/origins.ts b/web/packages/next/origins.ts
index 4e604445b6..8200df95a3 100644
--- a/web/packages/next/origins.ts
+++ b/web/packages/next/origins.ts
@@ -1,4 +1,4 @@
-import { get, set } from "idb-keyval";
+import { getKV, setKV } from "@/next/kv";
/**
* Return the origin (scheme, host, port triple) that should be used for making
@@ -35,14 +35,14 @@ export const apiURL = async (path: string) => (await apiOrigin()) + path;
* Otherwise return undefined.
*/
export const customAPIOrigin = async () => {
- let origin = await get<string>("apiOrigin");
+ let origin = await getKV("apiOrigin");
if (!origin) {
// TODO: Migration of apiOrigin from local storage to indexed DB
// Remove me after a bit (27 June 2024).
const legacyOrigin = localStorage.getItem("apiOrigin");
if (legacyOrigin !== null) {
origin = legacyOrigin;
- if (origin) await set("apiOrigin", origin);
+ if (origin) await setKV("apiOrigin", origin);
localStorage.removeItem("apiOrigin");
}
}
diff --git a/web/packages/next/package.json b/web/packages/next/package.json
index 311b02870e..00392569bb 100644
--- a/web/packages/next/package.json
+++ b/web/packages/next/package.json
@@ -11,7 +11,6 @@
"get-user-locale": "^2.3",
"i18next": "^23.10",
"i18next-resources-to-backend": "^1.2.0",
- "idb-keyval": "^6",
"is-electron": "^2.2",
"next": "^14.1",
"react": "^18",
diff --git a/web/yarn.lock b/web/yarn.lock
index 1a89c87063..be1c37c63d 100644
--- a/web/yarn.lock
+++ b/web/yarn.lock
@@ -2922,11 +2922,6 @@ i18next@^23.10:
dependencies:
"@babel/runtime" "^7.23.2"
-idb-keyval@^6:
- version "6.2.1"
- resolved "https://registry.yarnpkg.com/idb-keyval/-/idb-keyval-6.2.1.tgz#94516d625346d16f56f3b33855da11bfded2db33"
- integrity sha512-8Sb3veuYCyrZL+VBt9LJfZjLUPWVvqn8tG28VqYNFCo43KHcKuq+b4EiXGeuaLAQWL2YmyDgMp2aSpH9JHsEQg==
-
idb@^8:
version "8.0.0"
resolved "https://registry.yarnpkg.com/idb/-/idb-8.0.0.tgz#33d7ed894ed36e23bcb542fb701ad579bfaad41f"