mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-02-14 21:27:20 +00:00
fix(admin): frequent query requests in the search (#7854)
This commit is contained in:
@@ -6,36 +6,14 @@ import {
|
||||
} from '@affine/admin/components/ui/card';
|
||||
import { ScrollArea } from '@affine/admin/components/ui/scroll-area';
|
||||
import { Separator } from '@affine/admin/components/ui/separator';
|
||||
import { useQueryImmutable } from '@affine/core/hooks/use-query';
|
||||
import { getServerServiceConfigsQuery } from '@affine/graphql';
|
||||
|
||||
import { AboutAFFiNE } from './about';
|
||||
|
||||
type ServerConfig = {
|
||||
externalUrl: string;
|
||||
https: boolean;
|
||||
host: string;
|
||||
port: number;
|
||||
path: string;
|
||||
};
|
||||
|
||||
type MailerConfig = {
|
||||
host: string;
|
||||
port: number;
|
||||
sender: string;
|
||||
};
|
||||
|
||||
type DatabaseConfig = {
|
||||
host: string;
|
||||
port: number;
|
||||
user: string;
|
||||
database: string;
|
||||
};
|
||||
|
||||
type ServerServiceConfig = {
|
||||
name: string;
|
||||
config: ServerConfig | MailerConfig | DatabaseConfig;
|
||||
};
|
||||
import type {
|
||||
DatabaseConfig,
|
||||
MailerConfig,
|
||||
ServerConfig,
|
||||
} from './use-server-service-configs';
|
||||
import { useServerServiceConfigs } from './use-server-service-configs';
|
||||
|
||||
export function ConfigPage() {
|
||||
return (
|
||||
@@ -166,22 +144,8 @@ const MailerCard = ({ mailerConfig }: { mailerConfig?: MailerConfig }) => {
|
||||
};
|
||||
|
||||
export function ServerServiceConfig() {
|
||||
const { data } = useQueryImmutable({
|
||||
query: getServerServiceConfigsQuery,
|
||||
});
|
||||
const server = data.serverServiceConfigs.find(
|
||||
(service: ServerServiceConfig) => service.name === 'server'
|
||||
);
|
||||
const mailer = data.serverServiceConfigs.find(
|
||||
(service: ServerServiceConfig) => service.name === 'mailer'
|
||||
);
|
||||
const database = data.serverServiceConfigs.find(
|
||||
(service: ServerServiceConfig) => service.name === 'database'
|
||||
);
|
||||
|
||||
const serverConfig = server?.config as ServerConfig | undefined;
|
||||
const mailerConfig = mailer?.config as MailerConfig | undefined;
|
||||
const databaseConfig = database?.config as DatabaseConfig | undefined;
|
||||
const { serverConfig, mailerConfig, databaseConfig } =
|
||||
useServerServiceConfigs();
|
||||
|
||||
return (
|
||||
<div className="flex flex-col py-5 px-6">
|
||||
|
||||
@@ -0,0 +1,62 @@
|
||||
import { useQueryImmutable } from '@affine/core/hooks/use-query';
|
||||
import { getServerServiceConfigsQuery } from '@affine/graphql';
|
||||
import { useMemo } from 'react';
|
||||
|
||||
export type ServerConfig = {
|
||||
externalUrl: string;
|
||||
https: boolean;
|
||||
host: string;
|
||||
port: number;
|
||||
path: string;
|
||||
};
|
||||
|
||||
export type MailerConfig = {
|
||||
host: string;
|
||||
port: number;
|
||||
sender: string;
|
||||
};
|
||||
|
||||
export type DatabaseConfig = {
|
||||
host: string;
|
||||
port: number;
|
||||
user: string;
|
||||
database: string;
|
||||
};
|
||||
|
||||
export type ServerServiceConfig = {
|
||||
name: string;
|
||||
config: ServerConfig | MailerConfig | DatabaseConfig;
|
||||
};
|
||||
|
||||
export const useServerServiceConfigs = () => {
|
||||
const { data } = useQueryImmutable({
|
||||
query: getServerServiceConfigsQuery,
|
||||
});
|
||||
const server = useMemo(
|
||||
() =>
|
||||
data.serverServiceConfigs.find(
|
||||
(service: ServerServiceConfig) => service.name === 'server'
|
||||
),
|
||||
[data.serverServiceConfigs]
|
||||
);
|
||||
const mailer = useMemo(
|
||||
() =>
|
||||
data.serverServiceConfigs.find(
|
||||
(service: ServerServiceConfig) => service.name === 'mailer'
|
||||
),
|
||||
[data.serverServiceConfigs]
|
||||
);
|
||||
const database = useMemo(
|
||||
() =>
|
||||
data.serverServiceConfigs.find(
|
||||
(service: ServerServiceConfig) => service.name === 'database'
|
||||
),
|
||||
[data.serverServiceConfigs]
|
||||
);
|
||||
|
||||
const serverConfig = server?.config as ServerConfig | undefined;
|
||||
const mailerConfig = mailer?.config as MailerConfig | undefined;
|
||||
const databaseConfig = database?.config as DatabaseConfig | undefined;
|
||||
|
||||
return { serverConfig, mailerConfig, databaseConfig };
|
||||
};
|
||||
Reference in New Issue
Block a user