Skip to content

armgit / memos

Public Imported from GitHub
0

Memos is an open-source, self-hosted note-taking app that brings your everyday thoughts together in a personal timeline. Your data stays yours, and you choose what to keep private or share.

fix: clean duplicated requests

johnnyjoy7817947f6644
diff --git a/web/src/components/HomeSidebar/TagsSection.tsx b/web/src/components/HomeSidebar/TagsSection.tsx
index 66b278e61..180d8340b 100644
--- a/web/src/components/HomeSidebar/TagsSection.tsx
+++ b/web/src/components/HomeSidebar/TagsSection.tsx
@@ -29,7 +29,14 @@ const TagsSection = (props: Props) => {
.sort((a, b) => a[0].localeCompare(b[0]))
.sort((a, b) => b[1] - a[1]);
- useDebounce(() => fetchTags(), 300, [memoList.size(), location.pathname]);
+ useDebounce(
+ () => {
+ if (memoList.size() === 0) return;
+ fetchTags();
+ },
+ 300,
+ [memoList.size(), location.pathname],
+ );
const fetchTags = async () => {
await tagStore.fetchTags({ user, location });
diff --git a/web/src/components/MemoEditor/ActionButton/AddMemoRelationPopover.tsx b/web/src/components/MemoEditor/ActionButton/AddMemoRelationPopover.tsx
index 77d800d35..eba9f89f9 100644
--- a/web/src/components/MemoEditor/ActionButton/AddMemoRelationPopover.tsx
+++ b/web/src/components/MemoEditor/ActionButton/AddMemoRelationPopover.tsx
@@ -39,6 +39,8 @@ const AddMemoRelationPopover = (props: Props) => {
useDebounce(
async () => {
+ if (!popoverOpen) return;
+
setIsFetching(true);
try {
const filters = [`creator == "${user.name}"`, `row_status == "NORMAL"`];
@@ -57,7 +59,7 @@ const AddMemoRelationPopover = (props: Props) => {
setIsFetching(false);
},
300,
- [searchText],
+ [popoverOpen, searchText],
);
const getHighlightedContent = (content: string) => {
diff --git a/web/src/components/MemoEditor/ActionButton/TagSelector.tsx b/web/src/components/MemoEditor/ActionButton/TagSelector.tsx
index 901976902..3c864e86a 100644
--- a/web/src/components/MemoEditor/ActionButton/TagSelector.tsx
+++ b/web/src/components/MemoEditor/ActionButton/TagSelector.tsx
@@ -1,8 +1,9 @@
import { Dropdown, IconButton, Menu, MenuButton } from "@mui/joy";
import { HashIcon } from "lucide-react";
-import { useEffect, useRef, useState } from "react";
+import { useRef, useState } from "react";
import useClickAway from "react-use/lib/useClickAway";
import OverflowTip from "@/components/kit/OverflowTip";
+import useAsyncEffect from "@/hooks/useAsyncEffect";
import useCurrentUser from "@/hooks/useCurrentUser";
import { useTagStore } from "@/store/v1";
import { useTranslate } from "@/utils/i18n";
@@ -21,15 +22,15 @@ const TagSelector = (props: Props) => {
const tags = tagStore.sortedTags();
const user = useCurrentUser();
- useEffect(() => {
- (async () => {
- try {
- await tagStore.fetchTags({ user });
- } catch (error) {
- // do nothing.
- }
- })();
- }, []);
+ useAsyncEffect(async () => {
+ if (!open) return;
+
+ try {
+ await tagStore.fetchTags({ user });
+ } catch (error) {
+ // do nothing.
+ }
+ }, [open]);
useClickAway(containerRef, () => {
setOpen(false);
diff --git a/web/src/components/MemoEditor/index.tsx b/web/src/components/MemoEditor/index.tsx
index e05205e99..2d6ec8e47 100644
--- a/web/src/components/MemoEditor/index.tsx
+++ b/web/src/components/MemoEditor/index.tsx
@@ -312,7 +312,6 @@ const MemoEditor = (props: Props) => {
memoPatch.relations = state.relationList;
}
const memo = await memoStore.updateMemo(memoPatch, updateMask);
- await memoStore.getOrFetchMemoByName(memo.name, { skipCache: true });
if (onConfirm) {
onConfirm(memo.name);
}
@@ -338,7 +337,6 @@ const MemoEditor = (props: Props) => {
})
.then((memo) => memo);
const memo = await request;
- await memoStore.getOrFetchMemoByName(memo.name, { skipCache: true });
if (onConfirm) {
onConfirm(memo.name);
}
diff --git a/web/src/components/UserStatisticsView.tsx b/web/src/components/UserStatisticsView.tsx
index 54376df63..3ad741ac7 100644
--- a/web/src/components/UserStatisticsView.tsx
+++ b/web/src/components/UserStatisticsView.tsx
@@ -9,7 +9,7 @@ import { memoServiceClient } from "@/grpcweb";
import useAsyncEffect from "@/hooks/useAsyncEffect";
import useCurrentUser from "@/hooks/useCurrentUser";
import i18n from "@/i18n";
-import { useMemoFilterStore, useMemoStore } from "@/store/v1";
+import { useMemoFilterStore, useMemoList, useMemoStore } from "@/store/v1";
import { useTranslate } from "@/utils/i18n";
import ActivityCalendar from "./ActivityCalendar";
import { Popover, PopoverContent, PopoverTrigger } from "./ui/Popover";
@@ -25,6 +25,7 @@ const UserStatisticsView = () => {
const t = useTranslate();
const currentUser = useCurrentUser();
const memoStore = useMemoStore();
+ const memoList = useMemoList();
const memoFilterStore = useMemoFilterStore();
const [memoAmount, setMemoAmount] = useState(0);
const [memoStats, setMemoStats] = useState<UserMemoStats>({ link: 0, taskList: 0, code: 0, incompleteTasks: 0 });
@@ -34,6 +35,8 @@ const UserStatisticsView = () => {
const days = Math.ceil((Date.now() - currentUser.createTime!.getTime()) / 86400000);
useAsyncEffect(async () => {
+ if (memoList.size() === 0) return;
+
const { entities } = await memoServiceClient.listMemoProperties({
name: `memos/-`,
});