瀏覽代碼

URL => id, which is what it is

Manav Rathi 1 年之前
父節點
當前提交
edd9c94d73

+ 17 - 21
web/apps/photos/src/components/ml/PeopleList.tsx

@@ -61,8 +61,8 @@ export const PeopleList = React.memo((props: PeopleListProps) => {
                     }
                     }
                 >
                 >
                     <FaceCropImageView
                     <FaceCropImageView
-                        url={person.displayImageUrl}
                         faceId={person.displayFaceId}
                         faceId={person.displayFaceId}
+                        cacheKey={person.faceCropCacheKey}
                     />
                     />
                 </FaceChip>
                 </FaceChip>
             ))}
             ))}
@@ -141,7 +141,7 @@ export function UnidentifiedFaces(props: {
                         <FaceChip key={index}>
                         <FaceChip key={index}>
                             <FaceCropImageView
                             <FaceCropImageView
                                 faceId={face.id}
                                 faceId={face.id}
-                                url={face.crop?.imageUrl}
+                                cacheKey={face.crop?.cacheKey}
                             />
                             />
                         </FaceChip>
                         </FaceChip>
                     ))}
                     ))}
@@ -151,13 +151,13 @@ export function UnidentifiedFaces(props: {
 }
 }
 
 
 interface FaceCropImageViewProps {
 interface FaceCropImageViewProps {
-    url: string;
     faceId: string;
     faceId: string;
+    cacheKey?: string;
 }
 }
 
 
 const FaceCropImageView: React.FC<FaceCropImageViewProps> = ({
 const FaceCropImageView: React.FC<FaceCropImageViewProps> = ({
-    url,
     faceId,
     faceId,
+    cacheKey,
 }) => {
 }) => {
     const [objectURL, setObjectURL] = useState<string | undefined>();
     const [objectURL, setObjectURL] = useState<string | undefined>();
 
 
@@ -165,22 +165,18 @@ const FaceCropImageView: React.FC<FaceCropImageViewProps> = ({
         let didCancel = false;
         let didCancel = false;
 
 
         async function loadImage() {
         async function loadImage() {
-            let blob: Blob;
-            if (!url) {
-                blob = undefined;
-            } else {
-                blob = await cachedOrNew("face-crops", url, async () => {
-                    const user = await ensureLocalUser();
-                    return machineLearningService.regenerateFaceCrop(
-                        user.token,
-                        user.id,
-                        faceId,
-                    );
-                });
-            }
-
-            if (didCancel) return;
-            setObjectURL(blob ? URL.createObjectURL(blob) : undefined);
+            const blob = cacheKey
+                ? await cachedOrNew("face-crops", cacheKey, async () => {
+                      const user = await ensureLocalUser();
+                      return machineLearningService.regenerateFaceCrop(
+                          user.token,
+                          user.id,
+                          faceId,
+                      );
+                  })
+                : undefined;
+            if (!didCancel)
+                setObjectURL(blob ? URL.createObjectURL(blob) : undefined);
         }
         }
 
 
         loadImage();
         loadImage();
@@ -189,7 +185,7 @@ const FaceCropImageView: React.FC<FaceCropImageViewProps> = ({
             didCancel = true;
             didCancel = true;
             if (objectURL) URL.revokeObjectURL(objectURL);
             if (objectURL) URL.revokeObjectURL(objectURL);
         };
         };
-    }, [url, faceId]);
+    }, [faceId, cacheKey]);
 
 
     return objectURL ? (
     return objectURL ? (
         <img src={objectURL} />
         <img src={objectURL} />

+ 2 - 7
web/apps/photos/src/services/machineLearning/faceService.ts

@@ -229,13 +229,8 @@ class FaceService {
         const blobOptions = syncContext.config.faceCrop.blobOptions;
         const blobOptions = syncContext.config.faceCrop.blobOptions;
         const blob = await imageBitmapToBlob(faceCrop.image, blobOptions);
         const blob = await imageBitmapToBlob(faceCrop.image, blobOptions);
 
 
-        const faceCropUrl = `/${face.id}`;
-        const faceCropCache = await openCache("face-crops");
-        await faceCropCache.put(faceCropUrl, blob);
-        face.crop = {
-            imageUrl: faceCropUrl,
-            imageBox: faceCrop.imageBox,
-        };
+        const cache = await openCache("face-crops");
+        await cache.put(face.id, blob);
 
 
         faceCrop.image.close();
         faceCrop.image.close();
 
 

+ 2 - 2
web/apps/photos/src/services/machineLearning/peopleService.ts

@@ -62,7 +62,7 @@ class PeopleService {
                 (a, b) => b.detection.probability - a.detection.probability,
                 (a, b) => b.detection.probability - a.detection.probability,
             );
             );
 
 
-            if (personFace && !personFace.crop?.imageUrl) {
+            if (personFace && !personFace.crop?.cacheKey) {
                 const file = await getLocalFile(personFace.fileId);
                 const file = await getLocalFile(personFace.fileId);
                 const imageBitmap = await getOriginalImageBitmap(file);
                 const imageBitmap = await getOriginalImageBitmap(file);
                 await FaceService.saveFaceCrop(
                 await FaceService.saveFaceCrop(
@@ -76,7 +76,7 @@ class PeopleService {
                 id: index,
                 id: index,
                 files: faces.map((f) => f.fileId),
                 files: faces.map((f) => f.fileId),
                 displayFaceId: personFace?.id,
                 displayFaceId: personFace?.id,
-                displayImageUrl: personFace?.crop?.imageUrl,
+                faceCropCacheKey: personFace?.crop?.cacheKey,
             };
             };
 
 
             await mlIDbStorage.putPerson(person);
             await mlIDbStorage.putPerson(person);

+ 2 - 2
web/apps/photos/src/types/machineLearning/index.ts

@@ -90,7 +90,7 @@ export interface FaceCrop {
 }
 }
 
 
 export interface StoredFaceCrop {
 export interface StoredFaceCrop {
-    imageUrl: string;
+    cacheKey: string;
     imageBox: Box;
     imageBox: Box;
 }
 }
 
 
@@ -128,7 +128,7 @@ export interface Person {
     name?: string;
     name?: string;
     files: Array<number>;
     files: Array<number>;
     displayFaceId?: string;
     displayFaceId?: string;
-    displayImageUrl?: string;
+    faceCropCacheKey?: string;
 }
 }
 
 
 export interface MlFileData {
 export interface MlFileData {