mirror of
https://github.com/kmc7468/arkvault.git
synced 2026-02-04 08:06:56 +00:00
클라이언트가 시작될 때 삭제된 파일이나 디렉터리 정보를 IndexedDB에서 삭제하도록 개선
This commit is contained in:
@@ -39,6 +39,10 @@ export const storeDirectoryInfo = async (directoryInfo: DirectoryInfo) => {
|
||||
await filesystem.directory.put(directoryInfo);
|
||||
};
|
||||
|
||||
export const deleteDirectoryInfo = async (id: number) => {
|
||||
await filesystem.directory.delete(id);
|
||||
};
|
||||
|
||||
export const getFileInfos = async (parentId: DirectoryId) => {
|
||||
return await filesystem.file.where({ parentId }).toArray();
|
||||
};
|
||||
@@ -50,3 +54,33 @@ export const getFileInfo = async (id: number) => {
|
||||
export const storeFileInfo = async (fileInfo: FileInfo) => {
|
||||
await filesystem.file.put(fileInfo);
|
||||
};
|
||||
|
||||
export const deleteFileInfo = async (id: number) => {
|
||||
await filesystem.file.delete(id);
|
||||
};
|
||||
|
||||
export const cleanupDanglingInfos = async () => {
|
||||
const validDirectoryIds: number[] = [];
|
||||
const validFileIds: number[] = [];
|
||||
const queue: DirectoryId[] = ["root"];
|
||||
|
||||
while (true) {
|
||||
const directoryId = queue.shift();
|
||||
if (!directoryId) break;
|
||||
|
||||
const [subDirectories, files] = await Promise.all([
|
||||
filesystem.directory.where({ parentId: directoryId }).toArray(),
|
||||
filesystem.file.where({ parentId: directoryId }).toArray(),
|
||||
]);
|
||||
subDirectories.forEach(({ id }) => {
|
||||
validDirectoryIds.push(id);
|
||||
queue.push(id);
|
||||
});
|
||||
files.forEach(({ id }) => validFileIds.push(id));
|
||||
}
|
||||
|
||||
await Promise.all([
|
||||
filesystem.directory.where("id").noneOf(validDirectoryIds).delete(),
|
||||
filesystem.file.where("id").noneOf(validFileIds).delete(),
|
||||
]);
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user