Fix for reuse connections

This commit is contained in:
2024-05-13 12:49:40 +02:00
parent b59b82a080
commit e69450d1dc
4 changed files with 15 additions and 8 deletions

View File

@@ -2,7 +2,7 @@ use crate::{config::CONFIG, prisma::PrismaClient};
pub async fn get_prisma_client() -> PrismaClient { pub async fn get_prisma_client() -> PrismaClient {
let database_url: String = format!( let database_url: String = format!(
"postgresql://{}:{}@{}:{}/{}?connection_limit=1", "postgresql://{}:{}@{}:{}/{}?connection_limit=10",
CONFIG.postgres_user, CONFIG.postgres_user,
CONFIG.postgres_password, CONFIG.postgres_password,
CONFIG.postgres_host, CONFIG.postgres_host,

View File

@@ -1,11 +1,14 @@
pub mod types; pub mod types;
use once_cell::sync::Lazy;
use serde::de::DeserializeOwned; use serde::de::DeserializeOwned;
use crate::config::CONFIG; use crate::config::CONFIG;
use self::types::{BaseBook, Page}; use self::types::{BaseBook, Page};
pub static CLIENT: Lazy<reqwest::Client> = Lazy::new(reqwest::Client::new);
async fn _make_request<T>( async fn _make_request<T>(
url: &str, url: &str,
params: Vec<(&str, String)>, params: Vec<(&str, String)>,
@@ -13,11 +16,9 @@ async fn _make_request<T>(
where where
T: DeserializeOwned, T: DeserializeOwned,
{ {
let client = reqwest::Client::new();
let formated_url = format!("{}{}", CONFIG.library_url, url); let formated_url = format!("{}{}", CONFIG.library_url, url);
let response = client let response = CLIENT
.get(formated_url) .get(formated_url)
.query(&params) .query(&params)
.header("Authorization", CONFIG.library_api_key.clone()) .header("Authorization", CONFIG.library_api_key.clone())

View File

@@ -1,8 +1,11 @@
use once_cell::sync::Lazy;
use reqwest::{Response, StatusCode}; use reqwest::{Response, StatusCode};
use serde::Deserialize; use serde::Deserialize;
use crate::config::CONFIG; use crate::config::CONFIG;
pub static CLIENT: Lazy<reqwest::Client> = Lazy::new(reqwest::Client::new);
#[derive(Deserialize)] #[derive(Deserialize)]
pub struct FilenameData { pub struct FilenameData {
pub filename: String, pub filename: String,
@@ -19,7 +22,7 @@ pub async fn download_from_downloader(
CONFIG.downloader_url CONFIG.downloader_url
); );
let response = reqwest::Client::new() let response = CLIENT
.get(url) .get(url)
.header("Authorization", &CONFIG.downloader_api_key) .header("Authorization", &CONFIG.downloader_api_key)
.send() .send()
@@ -42,7 +45,7 @@ pub async fn get_filename(
CONFIG.downloader_url CONFIG.downloader_url
); );
let response = reqwest::Client::new() let response = CLIENT
.get(url) .get(url)
.header("Authorization", &CONFIG.downloader_api_key) .header("Authorization", &CONFIG.downloader_api_key)
.send() .send()

View File

@@ -1,4 +1,5 @@
use base64::{engine::general_purpose, Engine}; use base64::{engine::general_purpose, Engine};
use once_cell::sync::Lazy;
use reqwest::{ use reqwest::{
header, header,
multipart::{Form, Part}, multipart::{Form, Part},
@@ -8,6 +9,8 @@ use serde::Deserialize;
use crate::config::CONFIG; use crate::config::CONFIG;
pub static CLIENT: Lazy<reqwest::Client> = Lazy::new(reqwest::Client::new);
#[derive(Deserialize)] #[derive(Deserialize)]
pub struct UploadData { pub struct UploadData {
pub chat_id: i64, pub chat_id: i64,
@@ -29,7 +32,7 @@ pub async fn download_from_telegram_files(
CONFIG.files_url CONFIG.files_url
); );
let response = reqwest::Client::new() let response = CLIENT
.get(url) .get(url)
.header("Authorization", CONFIG.files_api_key.clone()) .header("Authorization", CONFIG.files_api_key.clone())
.send() .send()
@@ -72,7 +75,7 @@ pub async fn upload_to_telegram_files(
.text("filename", filename) .text("filename", filename)
.part("file", part); .part("file", part);
let response = reqwest::Client::new() let response = CLIENT
.post(url) .post(url)
.header("Authorization", CONFIG.files_api_key.clone()) .header("Authorization", CONFIG.files_api_key.clone())
.multipart(form) .multipart(form)