diff --git a/web/packages/gallery/services/video.ts b/web/packages/gallery/services/video.ts index 02a0b93c36..b5abd7a3ef 100644 --- a/web/packages/gallery/services/video.ts +++ b/web/packages/gallery/services/video.ts @@ -516,16 +516,7 @@ const blobToDataURL = (blob: Blob) => * an array. */ const savedProcessedVideoFileIDs = () => - // [Note: Avoiding Zod parsing overhead for DB arrays] - // - // Validating that the value we read from the DB is indeed the same as the - // type we expect can be done using Zod, but for potentially very large - // arrays, this has an overhead that is perhaps not justified when dealing - // with DB entries we ourselves wrote. - // - // As an optimization, we skip the runtime check here and cast. This might - // not be the most optimal choice in the future, so (a) use it sparingly, - // and (b) mark all such cases with the title of this note. + // See: [Note: Avoiding Zod parsing for large DB arrays] getKV("videoPreviewProcessedFileIDs").then((v) => new Set(v as number[])); /** @@ -535,7 +526,7 @@ const savedProcessedVideoFileIDs = () => * @see also {@link savedProcessedVideoFileIDs}. */ const savedFailedVideoFileIDs = () => - // See: [Note: Avoiding Zod parsing overhead for DB arrays] + // See: [Note: Avoiding Zod parsing for large DB arrays] getKV("videoPreviewFailedFileIDs").then((v) => new Set(v as number[])); /** diff --git a/web/packages/new/photos/services/photos-fdb.ts b/web/packages/new/photos/services/photos-fdb.ts index fff4d3bf87..687dff0fbe 100644 --- a/web/packages/new/photos/services/photos-fdb.ts +++ b/web/packages/new/photos/services/photos-fdb.ts @@ -2,10 +2,7 @@ * @file Photos app specific files DB. See: [Note: Files DB]. */ -import { - LocalCollections, - LocalEnteFiles, -} from "ente-gallery/services/files-db"; +import { LocalCollections } from "ente-gallery/services/files-db"; import { type Collection } from "ente-media/collection"; import type { EnteFile } from "ente-media/file"; import localForage from "ente-shared/storage/localForage"; @@ -123,13 +120,19 @@ export const savedFiles = async (): Promise => { * * Use {@link saveNormalFiles} to update the database. */ -export const savedNormalFiles = async (): Promise => { - const files: EnteFile[] = - (await localForage.getItem("files")) ?? []; - const fmany = Array(10000).fill(files).flat(); - console.time("file parse"); - const f2 = LocalEnteFiles.parse(fmany); - console.timeEnd("file parse"); - console.log(f2.length); - return files; -}; +export const savedNormalFiles = async (): Promise => + // [Note: Avoiding Zod parsing for large DB arrays] + // + // Zod can be used to validate that the value we read from the DB is indeed + // the same as the type we expect, but for potentially very large arrays, + // this has an overhead that is perhaps not justified when dealing with DB + // entries we ourselves wrote. + // + // For example (as a non-rigorous benchmark) parsing 200k files took one + // second. Zod is fast, just that these arrays are big and might be accessed + // frequently, and the schemas are, while not too complicated, non-trivial. + // + // As an optimization, we skip the runtime check here and cast. This might + // not be the most optimal choice in the future, so (a) use it sparingly, + // and (b) mark all such cases with the title of this note. + (await localForage.getItem("files")) ?? [];