- Do not clear temp files that are locked. (#6214)
- Handle edge cases in sync workspace
This commit is contained in:
parent
1a715c98b2
commit
ede4aad55b
4 changed files with 46 additions and 22 deletions
|
|
@ -59,10 +59,10 @@ export class Storage {
|
||||||
this.workspaceSlug = "";
|
this.workspaceSlug = "";
|
||||||
};
|
};
|
||||||
|
|
||||||
clearStorage = async () => {
|
clearStorage = async (force = false) => {
|
||||||
try {
|
try {
|
||||||
await this.db.close();
|
await this.db?.close();
|
||||||
await clearOPFS();
|
await clearOPFS(force);
|
||||||
this.reset();
|
this.reset();
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.error("Error clearing sqlite sync storage", e);
|
console.error("Error clearing sqlite sync storage", e);
|
||||||
|
|
|
||||||
|
|
@ -109,7 +109,7 @@ const syncLabels = async (currentLabels: any) => {
|
||||||
const currentIdList = currentLabels.map((label: any) => label.id);
|
const currentIdList = currentLabels.map((label: any) => label.id);
|
||||||
const existingLabels = await persistence.db.exec("SELECT id FROM labels;");
|
const existingLabels = await persistence.db.exec("SELECT id FROM labels;");
|
||||||
|
|
||||||
const existingIdList = existingLabels.map((label: any) => label.id);
|
const existingIdList = existingLabels ? existingLabels.map((label: any) => label.id) : [];
|
||||||
|
|
||||||
const deletedIds = difference(existingIdList, currentIdList);
|
const deletedIds = difference(existingIdList, currentIdList);
|
||||||
|
|
||||||
|
|
@ -140,7 +140,7 @@ export const syncIssuesWithDeletedLabels = async (deletedLabelIds: string[]) =>
|
||||||
const syncModules = async (currentModules: any) => {
|
const syncModules = async (currentModules: any) => {
|
||||||
const currentIdList = currentModules.map((module: any) => module.id);
|
const currentIdList = currentModules.map((module: any) => module.id);
|
||||||
const existingModules = await persistence.db.exec("SELECT id FROM modules;");
|
const existingModules = await persistence.db.exec("SELECT id FROM modules;");
|
||||||
const existingIdList = existingModules.map((module: any) => module.id);
|
const existingIdList = existingModules ? existingModules.map((module: any) => module.id) : [];
|
||||||
const deletedIds = difference(existingIdList, currentIdList);
|
const deletedIds = difference(existingIdList, currentIdList);
|
||||||
await syncIssuesWithDeletedModules(deletedIds as string[]);
|
await syncIssuesWithDeletedModules(deletedIds as string[]);
|
||||||
};
|
};
|
||||||
|
|
@ -167,7 +167,7 @@ export const syncIssuesWithDeletedModules = async (deletedModuleIds: string[]) =
|
||||||
const syncCycles = async (currentCycles: any) => {
|
const syncCycles = async (currentCycles: any) => {
|
||||||
const currentIdList = currentCycles.map((cycle: any) => cycle.id);
|
const currentIdList = currentCycles.map((cycle: any) => cycle.id);
|
||||||
const existingCycles = await persistence.db.exec("SELECT id FROM cycles;");
|
const existingCycles = await persistence.db.exec("SELECT id FROM cycles;");
|
||||||
const existingIdList = existingCycles.map((cycle: any) => cycle.id);
|
const existingIdList = existingCycles ? existingCycles.map((cycle: any) => cycle.id) : [];
|
||||||
const deletedIds = difference(existingIdList, currentIdList);
|
const deletedIds = difference(existingIdList, currentIdList);
|
||||||
await syncIssuesWithDeletedCycles(deletedIds as string[]);
|
await syncIssuesWithDeletedCycles(deletedIds as string[]);
|
||||||
};
|
};
|
||||||
|
|
@ -194,7 +194,7 @@ export const syncIssuesWithDeletedCycles = async (deletedCycleIds: string[]) =>
|
||||||
const syncStates = async (currentStates: any) => {
|
const syncStates = async (currentStates: any) => {
|
||||||
const currentIdList = currentStates.map((state: any) => state.id);
|
const currentIdList = currentStates.map((state: any) => state.id);
|
||||||
const existingStates = await persistence.db.exec("SELECT id FROM states;");
|
const existingStates = await persistence.db.exec("SELECT id FROM states;");
|
||||||
const existingIdList = existingStates.map((state: any) => state.id);
|
const existingIdList = existingStates ? existingStates.map((state: any) => state.id) : [];
|
||||||
const deletedIds = difference(existingIdList, currentIdList);
|
const deletedIds = difference(existingIdList, currentIdList);
|
||||||
await syncIssuesWithDeletedStates(deletedIds as string[]);
|
await syncIssuesWithDeletedStates(deletedIds as string[]);
|
||||||
};
|
};
|
||||||
|
|
@ -221,7 +221,7 @@ export const syncIssuesWithDeletedStates = async (deletedStateIds: string[]) =>
|
||||||
const syncMembers = async (currentMembers: any) => {
|
const syncMembers = async (currentMembers: any) => {
|
||||||
const currentIdList = currentMembers.map((member: any) => member.id);
|
const currentIdList = currentMembers.map((member: any) => member.id);
|
||||||
const existingMembers = await persistence.db.exec("SELECT id FROM members;");
|
const existingMembers = await persistence.db.exec("SELECT id FROM members;");
|
||||||
const existingIdList = existingMembers.map((member: any) => member.id);
|
const existingIdList = existingMembers ? existingMembers.map((member: any) => member.id) : [];
|
||||||
const deletedIds = difference(existingIdList, currentIdList);
|
const deletedIds = difference(existingIdList, currentIdList);
|
||||||
await syncIssuesWithDeletedMembers(deletedIds as string[]);
|
await syncIssuesWithDeletedMembers(deletedIds as string[]);
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -160,24 +160,48 @@ const parseSQLite3Error = (error: any) => {
|
||||||
return error;
|
return error;
|
||||||
};
|
};
|
||||||
|
|
||||||
export const clearOPFS = async () => {
|
export const isChrome = () => {
|
||||||
const storageManager = window.navigator.storage;
|
|
||||||
const fileSystemDirectoryHandle = await storageManager.getDirectory();
|
|
||||||
const userAgent = navigator.userAgent;
|
const userAgent = navigator.userAgent;
|
||||||
const isChrome = userAgent.includes("Chrome") && !userAgent.includes("Edg") && !userAgent.includes("OPR");
|
return userAgent.includes("Chrome") && !userAgent.includes("Edg") && !userAgent.includes("OPR");
|
||||||
|
};
|
||||||
|
|
||||||
if (isChrome) {
|
export const clearOPFS = async (force = false) => {
|
||||||
await (fileSystemDirectoryHandle as any).remove({ recursive: true });
|
const storageManager = window.navigator.storage;
|
||||||
|
const root = await storageManager.getDirectory();
|
||||||
|
|
||||||
|
if (force && isChrome()) {
|
||||||
|
await (root as any).remove({ recursive: true });
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
// ts-ignore
|
||||||
|
for await (const entry of root.values()) {
|
||||||
|
if (entry.kind === "directory" && entry.name.startsWith(".ahp-")) {
|
||||||
|
// A lock with the same name as the directory protects it from
|
||||||
|
// being deleted.
|
||||||
|
|
||||||
const entries = await (fileSystemDirectoryHandle as any).entries();
|
if (force) {
|
||||||
for await (const entry of entries) {
|
// don't wait for the lock
|
||||||
const [name] = entry;
|
try {
|
||||||
try {
|
await root.removeEntry(entry.name, { recursive: true });
|
||||||
await fileSystemDirectoryHandle.removeEntry(name);
|
} catch (e) {
|
||||||
} catch (e) {
|
console.log(e);
|
||||||
console.log("Error", e);
|
}
|
||||||
|
} else {
|
||||||
|
await navigator.locks.request(entry.name, { ifAvailable: true }, async (lock) => {
|
||||||
|
if (lock) {
|
||||||
|
log?.(`Deleting temporary directory ${entry.name}`);
|
||||||
|
try {
|
||||||
|
await root.removeEntry(entry.name, { recursive: true });
|
||||||
|
} catch (e) {
|
||||||
|
console.log(e);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
log?.(`Temporary directory ${entry.name} is in use`);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
root.removeEntry(entry.name);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -231,7 +231,7 @@ export class UserStore implements IUserStore {
|
||||||
*/
|
*/
|
||||||
signOut = async (): Promise<void> => {
|
signOut = async (): Promise<void> => {
|
||||||
await this.authService.signOut(API_BASE_URL);
|
await this.authService.signOut(API_BASE_URL);
|
||||||
await persistence.clearStorage();
|
await persistence.clearStorage(true);
|
||||||
this.store.resetOnSignOut();
|
this.store.resetOnSignOut();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue