-
Notifications
You must be signed in to change notification settings - Fork 3.6k
[WEB-2001] feat: Fix local cache issues r3 #5714
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
be8f069
215889c
00c48c3
5cece0f
44a2244
f8305a6
1bc6a0b
aaa59c1
594ea31
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -2,29 +2,33 @@ | |||||
|
|
||||||
| import React, { useState } from "react"; | ||||||
| import { observer } from "mobx-react"; | ||||||
| import { useParams } from "next/navigation"; | ||||||
| import { FileText, HelpCircle, MessagesSquare, MoveLeft, User } from "lucide-react"; | ||||||
| // ui | ||||||
| import { CustomMenu, Tooltip } from "@plane/ui"; | ||||||
| import { CustomMenu, ToggleSwitch, Tooltip } from "@plane/ui"; | ||||||
| // helpers | ||||||
| import { cn } from "@/helpers/common.helper"; | ||||||
| // hooks | ||||||
| import { useAppTheme, useCommandPalette, useInstance, useTransient } from "@/hooks/store"; | ||||||
| import { useAppTheme, useCommandPalette, useInstance, useTransient, useUserSettings } from "@/hooks/store"; | ||||||
| import { usePlatformOS } from "@/hooks/use-platform-os"; | ||||||
| // plane web components | ||||||
| import { PlaneVersionNumber, ProductUpdates, ProductUpdatesModal } from "@/plane-web/components/global"; | ||||||
| import { WorkspaceEditionBadge } from "@/plane-web/components/workspace"; | ||||||
| import { ENABLE_LOCAL_DB_CACHE } from "@/plane-web/constants/issues"; | ||||||
|
|
||||||
| export interface WorkspaceHelpSectionProps { | ||||||
| setSidebarActive?: React.Dispatch<React.SetStateAction<boolean>>; | ||||||
| } | ||||||
|
|
||||||
| export const SidebarHelpSection: React.FC<WorkspaceHelpSectionProps> = observer(() => { | ||||||
| const { workspaceSlug, projectId } = useParams(); | ||||||
| // store hooks | ||||||
| const { sidebarCollapsed, toggleSidebar } = useAppTheme(); | ||||||
| const { toggleShortcutModal } = useCommandPalette(); | ||||||
| const { isMobile } = usePlatformOS(); | ||||||
| const { config } = useInstance(); | ||||||
| const { isIntercomToggle, toggleIntercom } = useTransient(); | ||||||
| const { canUseLocalDB, toggleLocalDB } = useUserSettings(); | ||||||
| // states | ||||||
| const [isNeedHelpOpen, setIsNeedHelpOpen] = useState(false); | ||||||
| const [isChangeLogOpen, setIsChangeLogOpen] = useState(false); | ||||||
|
|
@@ -105,6 +109,23 @@ export const SidebarHelpSection: React.FC<WorkspaceHelpSectionProps> = observer( | |||||
| </a> | ||||||
| </CustomMenu.MenuItem> | ||||||
| <div className="my-1 border-t border-custom-border-200" /> | ||||||
| {ENABLE_LOCAL_DB_CACHE && ( | ||||||
| <CustomMenu.MenuItem> | ||||||
| <div | ||||||
| onClick={(e) => { | ||||||
| e.preventDefault(); | ||||||
| e.stopPropagation(); | ||||||
| }} | ||||||
| className="flex w-full items-center justify-between text-xs hover:bg-custom-background-80" | ||||||
| > | ||||||
| <span className="racking-tight">Local Cache</span> | ||||||
| <ToggleSwitch | ||||||
| value={canUseLocalDB} | ||||||
| onChange={() => toggleLocalDB(workspaceSlug?.toString(), projectId?.toString())} | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Handle potential 'undefined' values when calling When using optional chaining with Apply this diff to safely handle undefined values: -onChange={() => toggleLocalDB(workspaceSlug?.toString(), projectId?.toString())}
+onChange={() => toggleLocalDB(workspaceSlug ? workspaceSlug.toString() : '', projectId ? projectId.toString() : '')}Alternatively, ensure that 📝 Committable suggestion
Suggested change
|
||||||
| /> | ||||||
| </div> | ||||||
| </CustomMenu.MenuItem> | ||||||
| )} | ||||||
| <CustomMenu.MenuItem> | ||||||
| <button | ||||||
| type="button" | ||||||
|
|
||||||
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -54,6 +54,7 @@ export class Storage { | |||||||||||||||||||||||||||||||||
| const fileSystemDirectoryHandle = await storageManager.getDirectory(); | ||||||||||||||||||||||||||||||||||
| //@ts-expect-error , clear local issue cache | ||||||||||||||||||||||||||||||||||
| await fileSystemDirectoryHandle.remove({ recursive: true }); | ||||||||||||||||||||||||||||||||||
| this.reset(); | ||||||||||||||||||||||||||||||||||
| } catch (e) { | ||||||||||||||||||||||||||||||||||
| console.error("Error clearing sqlite sync storage", e); | ||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||
|
Comment on lines
54
to
60
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛠️ Refactor suggestion Consider improving error handling in The current implementation logs the error but doesn't propagate it. Consider either:
This would provide better visibility into storage clearing failures. Here's a suggested implementation: clearStorage = async () => {
try {
const storageManager = window.navigator.storage;
const fileSystemDirectoryHandle = await storageManager.getDirectory();
//@ts-expect-error , clear local issue cache
await fileSystemDirectoryHandle.remove({ recursive: true });
this.reset();
+ return true;
} catch (e) {
console.error("Error clearing sqlite sync storage", e);
+ return false;
}
};📝 Committable suggestion
Suggested change
|
||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -22,7 +22,7 @@ export interface IUserSettingsStore { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| canUseLocalDB: boolean; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // actions | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| fetchCurrentUserSettings: () => Promise<IUserSettings | undefined>; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| toggleLocalDB: () => Promise<void>; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| toggleLocalDB: (workspaceSlug: string | undefined, projectId: string | undefined) => Promise<void>; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛠️ Refactor suggestion Use optional parameter syntax for cleaner code In TypeScript, it's more idiomatic to use the optional parameter syntax Apply this diff to update the method signature: -toggleLocalDB: (workspaceSlug: string | undefined, projectId: string | undefined) => Promise<void>;
+toggleLocalDB: (workspaceSlug?: string, projectId?: string) => Promise<void>;📝 Committable suggestion
Suggested change
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| export class UserSettingsStore implements IUserSettingsStore { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -59,7 +59,7 @@ export class UserSettingsStore implements IUserSettingsStore { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| this.userService = new UserService(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| toggleLocalDB = async () => { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| toggleLocalDB = async (workspaceSlug: string | undefined, projectId: string | undefined) => { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛠️ Refactor suggestion Update method signature to use optional parameters Ensure that the implementation matches the interface update by using the optional parameter syntax in the method definition as well. Apply this diff to update the method signature: -toggleLocalDB = async (workspaceSlug: string | undefined, projectId: string | undefined) => {
+toggleLocalDB = async (workspaceSlug?: string, projectId?: string) => {📝 Committable suggestion
Suggested change
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const currentLocalDBValue = this.canUseLocalDB; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| try { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| runInAction(() => { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -70,8 +70,14 @@ export class UserSettingsStore implements IUserSettingsStore { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if (!transactionResult) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| throw new Error("error while toggling local DB"); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } else if (currentLocalDBValue) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if (currentLocalDBValue) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| await persistence.clearStorage(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } else if (workspaceSlug) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| await persistence.initialize(workspaceSlug); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| persistence.syncWorkspace(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| projectId && persistence.syncIssues(projectId); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+75
to
+80
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Await asynchronous operations to ensure proper execution If Apply this diff to await the asynchronous calls: - persistence.syncWorkspace();
- projectId && persistence.syncIssues(projectId);
+ await persistence.syncWorkspace();
+ if (projectId) {
+ await persistence.syncIssues(projectId);
+ }📝 Committable suggestion
Suggested change
Handle cases when 'workspaceSlug' is undefined during initialization When enabling the local database ( Consider adding validation to ensure that Apply this diff to add a warning when } else if (workspaceSlug) {
await persistence.initialize(workspaceSlug);
- persistence.syncWorkspace();
- projectId && persistence.syncIssues(projectId);
+ await persistence.syncWorkspace();
+ if (projectId) {
+ await persistence.syncIssues(projectId);
+ }
+ } else {
+ console.warn("Workspace slug is required to initialize local database");
}📝 Committable suggestion
Suggested change
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } catch (e) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| console.warn("error while toggling local DB"); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Typo in className 'racking-tight'
The className
racking-tightappears to be a typo. It should likely betracking-tight, which adjusts letter spacing.Apply this diff to fix the typo:
📝 Committable suggestion