filter files in trash

This commit is contained in:
Manav Rathi
2025-05-12 19:28:40 +05:30
parent 2adabc1e24
commit 96c3880e38
4 changed files with 23 additions and 12 deletions

View File

@@ -15,6 +15,7 @@ import { fileLogID, type EnteFile } from "ente-media/file";
import { FileType } from "ente-media/file-type";
import {
getAllLocalFiles,
getLocalTrashFileIDs,
uniqueFilesByID,
} from "ente-new/photos/services/files";
import { settingsSnapshot } from "ente-new/photos/services/settings";
@@ -711,15 +712,21 @@ const backfillQueue = async (
userID: number,
): Promise<VideoProcessingQueueItem[]> => {
const allCollectionFiles = await getAllLocalFiles();
const localTrashFileIDs = await getLocalTrashFileIDs();
const videoFiles = uniqueFilesByID(
allCollectionFiles.filter(
(f) =>
f.ownerID == userID &&
f.metadata.fileType == FileType.video &&
!localTrashFileIDs.has(f.id),
),
);
const doneIDs = (await savedProcessedVideoFileIDs()).union(
await savedFailedVideoFileIDs(),
);
const videoFiles = uniqueFilesByID(
allCollectionFiles.filter(
(f) => f.ownerID == userID && f.metadata.fileType == FileType.video,
),
);
const pendingVideoFiles = videoFiles.filter((f) => !doneIDs.has(f.id));
const batch = randomSample(pendingVideoFiles, 50);
return batch.map((file) => ({ file }));
};

View File

@@ -242,6 +242,13 @@ export function getTrashedFiles(trash: Trash): EnteFile[] {
);
}
/**
* Return the IDs of all the files that are part of the trash as per our local
* database.
*/
export const getLocalTrashFileIDs = () =>
getLocalTrash().then((trash) => new Set(trash.map((f) => f.file.id)));
const sortTrashFiles = (files: EnteFile[]) => {
return files.sort((a, b) => {
if (a.deleteBy === b.deleteBy) {

View File

@@ -255,7 +255,7 @@ export const addFileEntry = async (fileID: number) => {
*/
export const updateAssumingLocalFiles = async (
localFileIDs: number[],
localTrashFilesIDs: number[],
localTrashFilesIDs: Set<number>,
) => {
const db = await mlDB();
const tx = db.transaction(
@@ -268,14 +268,13 @@ export const updateAssumingLocalFiles = async (
.getAllKeys(IDBKeyRange.only("indexed"));
const local = new Set(localFileIDs);
const localTrash = new Set(localTrashFilesIDs);
const fdb = new Set(fdbFileIDs);
const fdbIndexed = new Set(fdbIndexedFileIDs);
const newFileIDs = localFileIDs.filter((id) => !fdb.has(id));
const removedFileIDs = fdbFileIDs.filter((id) => {
if (local.has(id)) return false; // Still exists.
if (localTrash.has(id)) {
if (localTrashFilesIDs.has(id)) {
// Exists in trash.
if (fdbIndexed.has(id)) {
// But is already indexed, so let it be.

View File

@@ -9,7 +9,7 @@ import { isNetworkDownloadError } from "ente-gallery/services/download";
import type { ProcessableUploadItem } from "ente-gallery/services/upload";
import { fileLogID, type EnteFile } from "ente-media/file";
import { wait } from "ente-utils/promise";
import { getAllLocalFiles, getLocalTrashedFiles } from "../files";
import { getAllLocalFiles, getLocalTrashFileIDs } from "../files";
import {
createImageBitmapAndData,
fetchRenderableBlob,
@@ -438,11 +438,9 @@ const syncWithLocalFilesAndGetFilesToIndex = async (
const localFiles = await getAllLocalFiles();
const localFileByID = new Map(localFiles.map((f) => [f.id, f]));
const localTrashFileIDs = (await getLocalTrashedFiles()).map((f) => f.id);
await updateAssumingLocalFiles(
Array.from(localFileByID.keys()),
localTrashFileIDs,
await getLocalTrashFileIDs(),
);
const fileIDsToIndex = await getIndexableFileIDs(count);