Skip to content

Commit

Permalink
perf: code
Browse files Browse the repository at this point in the history
  • Loading branch information
c121914yu committed Jun 15, 2023
1 parent bf1592d commit 6f9e929
Show file tree
Hide file tree
Showing 8 changed files with 53 additions and 17 deletions.
Binary file added client/public/imgs/errImg.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
19 changes: 19 additions & 0 deletions client/src/components/Markdown/Image.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import React, { useState } from 'react';
import { Image, Skeleton } from '@chakra-ui/react';

const MdImage = ({ src }: { src: string }) => {
const [isLoading, setIsLoading] = useState(true);
return (
<Skeleton minH="60px" isLoaded={!isLoading} fadeDuration={2}>
<Image
src={src}
alt={''}
fallbackSrc={'/imgs/errImg.png'}
onLoad={() => setIsLoading(false)}
onError={() => setIsLoading(false)}
/>
</Skeleton>
);
};

export default MdImage;
4 changes: 4 additions & 0 deletions client/src/components/Markdown/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import styles from './index.module.scss';
import CodeLight from './codeLight';
import Loading from './Loading';
import MermaidCodeBlock from './MermaidCodeBlock';
import MdImage from './Image';

const Markdown = ({
source,
Expand All @@ -33,6 +34,9 @@ const Markdown = ({
rehypePlugins={[rehypeKatex]}
components={{
pre: 'div',
img({ src = '' }) {
return <MdImage src={src} />;
},
code({ node, inline, className, children, ...props }) {
const match = /language-(\w+)/.exec(className || '');

Expand Down
5 changes: 5 additions & 0 deletions client/src/pages/api/openapi/kb/pushData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,9 @@ export async function pushDataToKb({
const set = new Set();
const filterData: DateItemType[] = [];

const time = Date.now();
console.log('push data', data.length);

data.forEach((item) => {
const text = item.q + item.a;

Expand Down Expand Up @@ -153,6 +156,8 @@ export async function pushDataToKb({

insertData.length > 0 && startQueue();

console.log('push data finish', Date.now() - time);

return {
insertLen: insertData.length
};
Expand Down
32 changes: 20 additions & 12 deletions client/src/pages/api/user/checkPayResult.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import { startQueue } from '@/service/utils/tools';
/* 校验支付结果 */
export default async function handler(req: NextApiRequest, res: NextApiResponse) {
try {
let { payId } = req.query as { payId: string };
const { payId } = req.query as { payId: string };

const { userId } = await authUser({ req, authToken: true });

Expand All @@ -34,10 +34,12 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse)
throw new Error('找不到用户');
}
// 获取邀请者
let inviter: UserModelSchema | null = null;
if (user.inviterId) {
inviter = await User.findById(user.inviterId);
}
const inviter = await (async () => {
if (user.inviterId) {
return User.findById(user.inviterId, '_id promotion');
}
return null;
})();

const payRes = await getPayResult(payOrder.orderId);

Expand Down Expand Up @@ -79,22 +81,28 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse)
unlockTask(userId);
}
} catch (error) {
await Pay.findByIdAndUpdate(payId, {
status: 'NOTPAY'
});
console.log(error);
try {
await Pay.findByIdAndUpdate(payId, {
status: 'NOTPAY'
});
} catch (error) {}
}
} else if (payRes.trade_state === 'CLOSED' || diffInHours > 24) {
return jsonRes(res, {
code: 500,
data: '更新订单失败,请重试'
});
}
if (payRes.trade_state === 'CLOSED' || diffInHours > 24) {
// 订单已关闭
await Pay.findByIdAndUpdate(payId, {
status: 'CLOSED'
});
jsonRes(res, {
return jsonRes(res, {
data: '订单已过期'
});
} else {
throw new Error(payRes?.trade_state_desc || '订单无效');
}
throw new Error(payRes?.trade_state_desc || '订单无效');
} catch (err) {
// console.log(err);
jsonRes(res, {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ ${e.password ? `密码为: ${e.password}` : ''}`;
<Box fontWeight={'bold'}>基本信息</Box>
<Flex alignItems={'center'} mt={4}>
<Box flex={'0 0 80px'} w={0}>
modelId
AppId
</Box>
<Box userSelect={'all'}>{getValues('_id')}</Box>
</Flex>
Expand Down
2 changes: 1 addition & 1 deletion client/src/pages/number/components/PayModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ const PayModal = ({ onClose }: { onClose: () => void }) => {
},
{
enabled: !!payId,
refetchInterval: 2000,
refetchInterval: 3000,
onSuccess(res) {
if (!res) return;
toast({
Expand Down
6 changes: 3 additions & 3 deletions client/src/service/mongo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,9 @@ export async function connectToDatabase(): Promise<void> {
global.mongodb = await mongoose.connect(process.env.MONGODB_URI as string, {
bufferCommands: true,
dbName: process.env.MONGODB_NAME,
maxPoolSize: 5,
minPoolSize: 1,
maxConnecting: 5
maxConnecting: 30,
maxPoolSize: 30,
minPoolSize: 10
});
console.log('mongo connected');
} catch (error) {
Expand Down

0 comments on commit 6f9e929

Please sign in to comment.