From 0c37cdf4036c6732312d363dee21dde02461d75a Mon Sep 17 00:00:00 2001 From: fantasticit Date: Tue, 24 May 2022 18:50:39 +0800 Subject: [PATCH] feat: improve data fetch --- packages/client/src/data/collector.tsx | 2 +- packages/client/src/data/document.tsx | 6 +++++- packages/client/src/pages/_app.tsx | 10 +++++++++- packages/client/src/pages/index.tsx | 1 - .../collaboration/collaboration/index.tsx | 18 ++++++------------ packages/server/src/app-cluster.service.ts | 2 +- 6 files changed, 22 insertions(+), 17 deletions(-) diff --git a/packages/client/src/data/collector.tsx b/packages/client/src/data/collector.tsx index 3518044..171a551 100644 --- a/packages/client/src/data/collector.tsx +++ b/packages/client/src/data/collector.tsx @@ -66,7 +66,7 @@ export const toggleCollectWiki = (wikiId, cookie = null): Promise => { * @returns */ export const useWikiCollectToggle = (wikiId) => { - const { data, error, refetch } = useQuery(`${CollectorApiDefinition.check.client()}?wikiId=${wikiId}`, () => + const { data, error, refetch } = useQuery([CollectorApiDefinition.check.client(), wikiId], () => getWikiIsCollected(wikiId) ); diff --git a/packages/client/src/data/document.tsx b/packages/client/src/data/document.tsx index 9efa5c6..6bdf5a6 100644 --- a/packages/client/src/data/document.tsx +++ b/packages/client/src/data/document.tsx @@ -296,7 +296,11 @@ export const getDocumentChildren = (data, cookie = null): Promise { const { data, error, refetch } = useQuery( - isShare ? DocumentApiDefinition.getPublicChildren.client() : DocumentApiDefinition.getChildren.client(), + [ + isShare ? DocumentApiDefinition.getPublicChildren.client() : DocumentApiDefinition.getChildren.client(), + wikiId, + documentId, + ], () => getDocumentChildren({ wikiId, documentId, isShare }) ); const loading = !data && !error; diff --git a/packages/client/src/pages/_app.tsx b/packages/client/src/pages/_app.tsx index f362d94..223610c 100644 --- a/packages/client/src/pages/_app.tsx +++ b/packages/client/src/pages/_app.tsx @@ -13,7 +13,15 @@ import { Hydrate, QueryClient, QueryClientProvider } from 'react-query'; class MyApp extends App<{ isMobile: boolean }> { state = { - queryClient: new QueryClient(), + queryClient: new QueryClient({ + defaultOptions: { + queries: { + refetchOnWindowFocus: true, + retry: false, + staleTime: 30000, + }, + }, + }), }; static getInitialProps = async ({ Component, ctx }) => { diff --git a/packages/client/src/pages/index.tsx b/packages/client/src/pages/index.tsx index ab36eeb..393fad7 100644 --- a/packages/client/src/pages/index.tsx +++ b/packages/client/src/pages/index.tsx @@ -65,7 +65,6 @@ const RecentDocs = () => { }} />, } />, - } />, - ) : ( -
- - {/* FIXME: semi-design 的问题,不加 div,文字会换行! */} -
-
-
- ) +
+ + {/* FIXME: semi-design 的问题,不加 div,文字会换行! */} +
+
+
} error={error} errorContent={(error) => ( diff --git a/packages/server/src/app-cluster.service.ts b/packages/server/src/app-cluster.service.ts index 4a7f2d5..380c849 100644 --- a/packages/server/src/app-cluster.service.ts +++ b/packages/server/src/app-cluster.service.ts @@ -3,7 +3,7 @@ import { Injectable } from '@nestjs/common'; import * as cluster from 'cluster'; import * as os from 'os'; -const numCPUs = os.cpus().length; +const numCPUs = os.cpus().length - 2; @Injectable() export class AppClusterService {