perf: pg
This commit is contained in:
@@ -23,7 +23,9 @@ export const pushChatBill = async ({
|
||||
// 计算 token 数量
|
||||
const tokens = Math.floor(encode(text).length * 0.75);
|
||||
|
||||
console.log(`chat generate success. text len: ${text.length}. token len: ${tokens}`);
|
||||
console.log(
|
||||
`chat generate success. text len: ${text.length}. token len: ${tokens}. pay:${isPay}`
|
||||
);
|
||||
|
||||
if (isPay) {
|
||||
await connectToDatabase();
|
||||
@@ -79,7 +81,9 @@ export const pushSplitDataBill = async ({
|
||||
let billId;
|
||||
|
||||
try {
|
||||
console.log(`splitData generate success. text len: ${text.length}. token len: ${tokenLen}`);
|
||||
console.log(
|
||||
`splitData generate success. text len: ${text.length}. token len: ${tokenLen}. pay:${isPay}`
|
||||
);
|
||||
|
||||
if (isPay) {
|
||||
try {
|
||||
@@ -130,7 +134,9 @@ export const pushGenerateVectorBill = async ({
|
||||
let billId;
|
||||
|
||||
try {
|
||||
console.log(`vector generate success. text len: ${text.length}. token len: ${tokenLen}`);
|
||||
console.log(
|
||||
`vector generate success. text len: ${text.length}. token len: ${tokenLen}. pay:${isPay}`
|
||||
);
|
||||
|
||||
if (isPay) {
|
||||
try {
|
||||
|
||||
@@ -16,7 +16,7 @@ export async function connectToDatabase(): Promise<void> {
|
||||
mongoose.set('strictQuery', true);
|
||||
global.mongodb = await mongoose.connect(process.env.MONGODB_URI as string, {
|
||||
bufferCommands: true,
|
||||
dbName: process.env.NODE_ENV === 'development' ? 'doc_gpt_test' : 'doc_gpt',
|
||||
dbName: process.env.MONGODB_NAME,
|
||||
maxPoolSize: 5,
|
||||
minPoolSize: 1,
|
||||
maxConnecting: 5
|
||||
|
||||
@@ -1,44 +0,0 @@
|
||||
import { createClient } from 'redis';
|
||||
import { customAlphabet } from 'nanoid';
|
||||
const nanoid = customAlphabet('abcdefghijklmnopqrstuvwxyz1234567890', 10);
|
||||
|
||||
export const connectRedis = async () => {
|
||||
// 断开了,重连
|
||||
if (global.redisClient && !global.redisClient.isOpen) {
|
||||
await global.redisClient.disconnect();
|
||||
} else if (global.redisClient) {
|
||||
// 没断开,不再连接
|
||||
return global.redisClient;
|
||||
}
|
||||
|
||||
try {
|
||||
global.redisClient = createClient({
|
||||
url: process.env.REDIS_URL
|
||||
});
|
||||
|
||||
global.redisClient.on('error', (err) => {
|
||||
console.log('Redis Client Error', err);
|
||||
global.redisClient = null;
|
||||
});
|
||||
global.redisClient.on('end', () => {
|
||||
global.redisClient = null;
|
||||
});
|
||||
global.redisClient.on('ready', () => {
|
||||
console.log('redis connected');
|
||||
});
|
||||
|
||||
await global.redisClient.connect();
|
||||
|
||||
await global.redisClient.SELECT(0);
|
||||
|
||||
return global.redisClient;
|
||||
} catch (error) {
|
||||
console.log(error, '==');
|
||||
global.redisClient = null;
|
||||
return Promise.reject('redis 连接失败');
|
||||
}
|
||||
};
|
||||
|
||||
export const getKey = (prefix = '') => {
|
||||
return `${prefix}:${nanoid()}`;
|
||||
};
|
||||
Reference in New Issue
Block a user