From bad48efe1217ec1406991a4e20da8e0dbc18955c Mon Sep 17 00:00:00 2001 From: "mimo.oyn" Date: Thu, 26 Dec 2024 16:13:04 +0800 Subject: [PATCH 1/2] fix: enhance blog list filter performance --- src/pages/blog/index.tsx | 76 +++++++++++++++++++++++++++------------- 1 file changed, 51 insertions(+), 25 deletions(-) diff --git a/src/pages/blog/index.tsx b/src/pages/blog/index.tsx index d06b93cd..716eb322 100644 --- a/src/pages/blog/index.tsx +++ b/src/pages/blog/index.tsx @@ -31,7 +31,6 @@ import Link from 'next/link'; import dayjs from 'dayjs'; import { Trans, useTranslation } from 'react-i18next'; import { InkeepCustomTriggerWrapper } from '@/components/inkeep/inkeepChat'; -import { debounce } from '@mui/material'; const PAGE_SIZE = 9; const TITLE = 'Learn Milvus: Insights and Innovations in VectorDB Technology'; @@ -241,7 +240,8 @@ const Blog: React.FC = props => { }, [filteredBlogs]); const generateLinkUrl = (...args: BlogLinkParam[]) => { - const search = new URLSearchParams(router.query as any); + const { [SEARCH_QUERY_KEY]: _, ...queryObject } = filter; + const search = new URLSearchParams(queryObject as any); args.forEach(({ key, value, shouldRemove }) => { if (shouldRemove) { search.delete(key); @@ -255,17 +255,43 @@ const Blog: React.FC = props => { return `${router.pathname}?${search.toString()}`; }; - const handleSearch = useCallback( - debounce((e: React.FormEvent) => { - const value = (e.target as HTMLInputElement).value.trim(); - const url = generateLinkUrl( - { key: SEARCH_QUERY_KEY, value, shouldRemove: !value }, - { key: PAGINATION_QUERY_KEY, value: 1, shouldRemove: true } - ); - router.replace(url, undefined, { scroll: false }); - }, 300), - [router] - ); + const handleSearch = (e: React.FormEvent) => { + const value = (e.target as HTMLInputElement).value.trim(); + const url = generateLinkUrl( + // { key: SEARCH_QUERY_KEY, value, shouldRemove: !value }, + { key: PAGINATION_QUERY_KEY, value: 1, shouldRemove: true } + ); + window.history.pushState({}, '', url); + setFilter(f => ({ + ...f, + [SEARCH_QUERY_KEY]: value, + [PAGINATION_QUERY_KEY]: 1, + })); + }; + + const handleFilter = (tag: BlogTag | 'all') => (e: React.MouseEvent) => { + // reduce list fetch when router change + e.preventDefault(); + const url = generateLinkUrl( + { key: TAG_QUERY_KEY, value: tag, shouldRemove: tag === DEFAULT_TAG }, + { key: PAGINATION_QUERY_KEY, value: 1, shouldRemove: true } + ); + window.history.pushState({}, '', url); + setFilter(f => ({ ...f, [TAG_QUERY_KEY]: tag, [PAGINATION_QUERY_KEY]: 1 })); + }; + + const handlePaging = (page: number) => (e: React.MouseEvent) => { + // reduce list fetch when router change + e.preventDefault(); + const url = generateLinkUrl({ + key: PAGINATION_QUERY_KEY, + value: page, + shouldRemove: page === 1, + }); + window.history.pushState({}, '', url); + setFilter(f => ({ ...f, [PAGINATION_QUERY_KEY]: page })); + scrollToListNav(); + }; const renderRecommend = () => { const { recommend } = blogs; @@ -351,16 +377,16 @@ const Blog: React.FC = props => { const renderFilterTagItem = (tag: BlogTag | typeof DEFAULT_TAG) => { const isActive = tag === (filter[TAG_QUERY_KEY] || DEFAULT_TAG); + const url = generateLinkUrl( + { + key: TAG_QUERY_KEY, + value: tag, + shouldRemove: tag === DEFAULT_TAG, + }, + { key: PAGINATION_QUERY_KEY, value: 1, shouldRemove: true } + ); return ( - +
= props => { = props => { ) : ( = props => { Date: Thu, 26 Dec 2024 16:33:08 +0800 Subject: [PATCH 2/2] fix: restful api link version --- src/blogs | 2 +- src/docs | 2 +- src/utils/apiReference.ts | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/blogs b/src/blogs index 7606b038..b72db034 160000 --- a/src/blogs +++ b/src/blogs @@ -1 +1 @@ -Subproject commit 7606b038255ed1bc7b6081dc2ec0b6d5db319778 +Subproject commit b72db0343377b55e360a3ef49d2c65a5af305254 diff --git a/src/docs b/src/docs index b5b2c7cd..32477142 160000 --- a/src/docs +++ b/src/docs @@ -1 +1 @@ -Subproject commit b5b2c7cd15c378ff69d21a5f7f2510c7576ec892 +Subproject commit 32477142052fb3a6dab6bf094ad54da1982a4999 diff --git a/src/utils/apiReference.ts b/src/utils/apiReference.ts index ac3810fb..d0733888 100644 --- a/src/utils/apiReference.ts +++ b/src/utils/apiReference.ts @@ -188,7 +188,7 @@ const API_REFERENCE_CONFIG = { }, [ApiReferenceLanguageEnum.Restful]: { name: ApiReferenceLabelEnum.Restful, - path: `${BASE_DOC_DIR}/API_Reference/${ApiReferenceLanguageEnum.Restful}`, + path: `${BASE_DOC_DIR}/API_Reference_MDX/${ApiReferenceLanguageEnum.Restful}`, minVersion: DOCS_MINIMUM_VERSION, category: ApiReferenceRouteEnum.Restful, },