Skip to content

Commit

Permalink
feat: add concurrency tower limit
Browse files Browse the repository at this point in the history
Signed-off-by: tsukinaha <sakuovds@gmail.com>
  • Loading branch information
tsukinaha committed Nov 20, 2024
1 parent 1f78458 commit 6054521
Show file tree
Hide file tree
Showing 9 changed files with 87 additions and 335 deletions.
22 changes: 22 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ md-5 = "0.10.6"
unicode-segmentation = "1.12.0"
hex = "0.4.3"
rand = "0.8.5"
tower = { version="0.5.1", features = ["limit"] }

[build-dependencies]
embed-resource = "3.0.1"
Expand Down
6 changes: 3 additions & 3 deletions resources/ui/account_settings.ui
Original file line number Diff line number Diff line change
Expand Up @@ -191,12 +191,12 @@
<child>
<object class="AdwSpinRow" id="threadspinrow">
<property name="title" translatable="yes">Threads</property>
<property name="subtitle" translatable="yes">This only effects on getting images</property>
<property name="subtitle" translatable="yes">This only effects on getting images/updating cache</property>
<property name="adjustment">
<object class="GtkAdjustment">
<property name="lower">1</property>
<property name="upper">2</property>
<property name="value">1</property>
<property name="upper">4</property>
<property name="value">2</property>
<property name="page-increment">1</property>
<property name="step-increment">1</property>
</object>
Expand Down
272 changes: 0 additions & 272 deletions src/client/dandan_client.rs

This file was deleted.

12 changes: 4 additions & 8 deletions src/client/emby_client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,7 @@ use anyhow::{
use once_cell::sync::Lazy;
use regex::Regex;
use reqwest::{
header::HeaderValue,
Method,
RequestBuilder,
Response,
header::HeaderValue, Client, Method, RequestBuilder, Response
};
use serde::{
de::DeserializeOwned,
Expand All @@ -24,6 +21,7 @@ use serde_json::{
json,
Value,
};
use tower::limit::ConcurrencyLimit;
use tracing::{
debug,
info,
Expand Down Expand Up @@ -83,7 +81,7 @@ pub enum BackType {

pub struct EmbyClient {
pub url: Mutex<Option<Url>>,
pub client: reqwest::Client,
pub client: ConcurrencyLimit<Client>,
pub headers: Mutex<reqwest::header::HeaderMap>,
pub user_id: Mutex<String>,
pub user_name: Mutex<String>,
Expand Down Expand Up @@ -279,7 +277,6 @@ impl EmbyClient {
where
T: for<'de> Deserialize<'de> + Send + 'static,
{
println!("request start");
let request = self.prepare_request(Method::GET, path, params)?;
let res = self.send_request(request).await?;

Expand All @@ -295,7 +292,6 @@ impl EmbyClient {

let res_text = res.text().await?;
debug!("Response: {}", res_text);
println!("request end");
match serde_json::from_str(&res_text) {
Ok(json) => Ok(json),
Err(e) => Err(anyhow!("Failed to parse JSON {}: {}", e, res_text)),
Expand Down Expand Up @@ -337,7 +333,7 @@ impl EmbyClient {
let (mut url, headers) = self.get_url_and_headers()?;
url = url.join(path)?;
self.add_params_to_url(&mut url, params);
Ok(self.client.request(method, url).headers(headers))
Ok(self.client.get_ref().request(method, url).headers(headers))
}

async fn send_request(&self, request: RequestBuilder) -> Result<Response> {
Expand Down
3 changes: 0 additions & 3 deletions src/client/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,3 @@ pub mod structs;

pub use account::Account;
pub use proxy::ReqClient;

#[allow(dead_code)]
pub mod dandan_client;
Loading

0 comments on commit 6054521

Please sign in to comment.