Skip to content

Commit

Permalink
revert: Cancel unnecessary asynchronous trait implementations
Browse files Browse the repository at this point in the history
  • Loading branch information
0x676e67 committed Feb 7, 2024
1 parent 2960a42 commit d674d11
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 16 deletions.
12 changes: 3 additions & 9 deletions crates/openai/src/auth/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -492,9 +492,7 @@ impl AuthClientBuilder {
}));

// Platform Login privider
providers.push(Prividers::Platform(PlatformAuthProvider(
client.clone(),
)));
providers.push(Prividers::Platform(PlatformAuthProvider(client.clone())));

AuthClient {
inner: client,
Expand Down Expand Up @@ -542,9 +540,7 @@ impl AuthProvider for Prividers {
Prividers::Web(provider) => provider.do_revoke_token(refresh_token).await,
#[cfg(feature = "preauth")]
Prividers::Apple(provider) => provider.do_revoke_token(refresh_token).await,
Prividers::Platform(provider) => {
provider.do_revoke_token(refresh_token).await
}
Prividers::Platform(provider) => provider.do_revoke_token(refresh_token).await,
}
}

Expand All @@ -553,9 +549,7 @@ impl AuthProvider for Prividers {
Prividers::Web(provider) => provider.do_refresh_token(refresh_token).await,
#[cfg(feature = "preauth")]
Prividers::Apple(provider) => provider.do_refresh_token(refresh_token).await,
Prividers::Platform(provider) => {
provider.do_refresh_token(refresh_token).await
}
Prividers::Platform(provider) => provider.do_refresh_token(refresh_token).await,
}
}
}
2 changes: 1 addition & 1 deletion crates/openai/src/serve/middleware/limit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ pub(crate) async fn limit_middleware<B>(
next: Next<B>,
) -> Result<Response, ResponseError> {
let addr = socket_addr.ip();
match limit.acquire(addr).await {
match limit.acquire(addr) {
Ok(condition) => match condition {
true => Ok(next.run(request).await),
false => Err(ResponseError::TooManyRequests(ProxyError::TooManyRequests)),
Expand Down
12 changes: 6 additions & 6 deletions crates/openai/src/serve/middleware/tokenbucket.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use crate::homedir::home_dir;
use crate::{context, debug, error, now_duration};

pub trait TokenBucket: Send + Sync {
async fn acquire(&self, ip: IpAddr) -> anyhow::Result<bool>;
fn acquire(&self, ip: IpAddr) -> anyhow::Result<bool>;
}

#[derive(Serialize, Deserialize, Clone, Debug)]
Expand Down Expand Up @@ -68,7 +68,7 @@ impl MemTokenBucket {
}

impl TokenBucket for MemTokenBucket {
async fn acquire(&self, ip: IpAddr) -> anyhow::Result<bool> {
fn acquire(&self, ip: IpAddr) -> anyhow::Result<bool> {
if !self.enable {
return Ok(true);
}
Expand Down Expand Up @@ -211,7 +211,7 @@ fn clear_expired_buckets_every(db: Arc<Database<'static>>, expired: u32) {
}

impl TokenBucket for RedisTokenBucket<'_> {
async fn acquire(&self, ip: IpAddr) -> anyhow::Result<bool> {
fn acquire(&self, ip: IpAddr) -> anyhow::Result<bool> {
if !self.enable {
return Ok(true);
}
Expand Down Expand Up @@ -291,10 +291,10 @@ impl From<(Strategy, bool, u32, u32, u32)> for TokenBucketProvider {
}

impl TokenBucket for TokenBucketProvider {
async fn acquire(&self, ip: IpAddr) -> anyhow::Result<bool> {
fn acquire(&self, ip: IpAddr) -> anyhow::Result<bool> {
let condition = match self {
Self::Mem(t) => t.acquire(ip).await,
Self::ReDB(t) => t.acquire(ip).await,
Self::Mem(t) => t.acquire(ip),
Self::ReDB(t) => t.acquire(ip),
};
Ok(condition?)
}
Expand Down

0 comments on commit d674d11

Please sign in to comment.