Skip to content

Commit 7dd380b

Browse files
committed
style(Backend): 🎨 manual clippy
1 parent 0458351 commit 7dd380b

27 files changed

+53
-198
lines changed

backend/Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,6 @@ optional = true
130130
features = ["runtime-tokio-rustls", "sqlx-sqlite", "with-chrono"]
131131

132132
[features]
133-
default = ["debug"]
133+
default = ["insecure-print"]
134134
standalone = ["dep:migration", "dep:sea-orm-migration", "dep:sea-orm-cli"]
135-
debug = ["sea-orm/debug-print"]
135+
insecure-print = ["sea-orm/debug-print"]

backend/src/controller/duplicate.rs

Lines changed: 0 additions & 62 deletions
This file was deleted.

backend/src/controller/judger/mod.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ use grpc::backend::StateCode as BackendCode;
1010
use sea_orm::{ActiveModelTrait, ActiveValue, DatabaseConnection, EntityTrait, QueryOrder};
1111
use thiserror::Error;
1212
use tonic::Status;
13-
use tracing::{instrument, Instrument, Span};
13+
use tracing::{instrument, Instrument};
1414
use uuid::Uuid;
1515

1616
use self::{pubsub::PubSub, route::*};
@@ -22,9 +22,6 @@ use grpc::{
2222
judger::*,
2323
};
2424

25-
const PALYGROUND_TIME: u64 = 500 * 1000;
26-
const PALYGROUND_MEM: u64 = 256 * 1024 * 1024;
27-
2825
#[derive(Debug, Error)]
2926
pub enum Error {
3027
#[error("judger temporarily unavailable")]

backend/src/controller/mod.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
//! include intergated test
55
66
pub mod crypto;
7-
pub mod duplicate;
87
pub mod imgur;
98
pub mod judger;
109
pub mod rate_limit;

backend/src/controller/rate_limit.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,6 @@ impl Bucket {
7575

7676
/// Policy of resource acquisition
7777
trait AcquisitionPolicy {
78-
const BUCKET_WIDTH: usize = BUCKET_WIDTH;
7978
/// How many burst request is allowed
8079
const BURST: NonZeroU32;
8180
/// How many fill per minute
@@ -145,7 +144,7 @@ impl RateLimitController {
145144
Self {
146145
ip_blacklist: Cache::new(BUCKET_WIDTH),
147146
user_limiter: Arc::new(LoginPolicy::key()),
148-
ip_limiter: Arc::new(LoginPolicy::key()),
147+
ip_limiter: Arc::new(GuestPolicy::key()),
149148
blacklist_limiter: Arc::new(BlacklistPolicy::direct()),
150149
trusts: trusts.to_vec(),
151150
}

backend/src/controller/token.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ use sea_orm::*;
77
use spin::Mutex;
88
use std::{ops::Deref, sync::Arc};
99
use tokio::time;
10-
use tracing::{instrument, Instrument, Span};
10+
use tracing::{instrument, Instrument};
1111

1212
use crate::report_internal;
1313

backend/src/endpoint/announcement.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
use super::tools::*;
1+
use super::*;
22

33
use grpc::backend::announcement_server::*;
44

55
use crate::{
66
entity::announcement::{Paginator, *},
7-
entity::*,
7+
entity::contest,
88
util::time::into_prost,
99
};
1010

backend/src/endpoint/chat.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use super::tools::*;
1+
use super::*;
22

33
use grpc::backend::chat_server::*;
44

backend/src/endpoint/contest.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use super::tools::*;
1+
use super::*;
22

33
use crate::entity::{
44
contest::{Paginator, *},

backend/src/endpoint/education.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
use super::tools::*;
1+
use super::*;
22

33
use grpc::backend::education_server::*;
44

5-
use crate::entity::{education::Paginator, education::*, *};
5+
use crate::entity::{education::Paginator, education::*, problem};
66

77
impl<'a> From<WithAuth<'a, Model>> for EducationFullInfo {
88
fn from(value: WithAuth<'a, Model>) -> Self {

backend/src/endpoint/imgur.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use super::tools::*;
1+
use super::*;
22

33
use grpc::backend::image_server::*;
44

backend/src/endpoint/mod.rs

Lines changed: 12 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -14,26 +14,17 @@ mod submit;
1414
mod testcase;
1515
mod token;
1616
mod user;
17-
mod util;
1817

19-
mod tools {
20-
pub use crate::NonZeroU32;
21-
pub use grpc::backend::{Id, Order, *};
22-
pub use sea_orm::*;
23-
pub use std::ops::Deref;
24-
pub use tonic::*;
25-
pub use tracing::*;
26-
pub use uuid::Uuid;
18+
use crate::NonZeroU32;
19+
use grpc::backend::{Id, Order, *};
20+
use sea_orm::*;
21+
use std::ops::Deref;
22+
use tonic::*;
23+
use tracing::*;
24+
use uuid::Uuid;
2725

28-
pub use crate::entity::util::{
29-
filter::*,
30-
paginator::{PaginateRaw, Remain},
31-
};
32-
pub use crate::util::with::*;
33-
pub use crate::util::{auth::RoleLv, bound::BoundCheck, duplicate::*, error::Error, time::*};
34-
pub use crate::{fill_active_model, fill_exist_active_model, server::ArcServer, TonicStream};
35-
pub use tracing::{Instrument, Level};
36-
}
37-
38-
// FIXME: currently we report transaction error as internal error,
39-
// but we should report it as bad request, or even a give it an retry logic
26+
use crate::entity::util::filter::*;
27+
use crate::util::with::*;
28+
use crate::util::{auth::RoleLv, bound::BoundCheck, duplicate::*, error::Error, time::*};
29+
use crate::{fill_active_model, fill_exist_active_model, server::ArcServer, TonicStream};
30+
use tracing::{Instrument, Level};

backend/src/endpoint/playground.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use super::tools::*;
1+
use super::*;
22

33
use grpc::backend::playground_server::*;
44
use grpc::backend::*;

backend/src/endpoint/problem.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
use super::tools::*;
1+
use super::*;
22
use grpc::backend::problem_server::*;
33

4-
use crate::entity::{problem::Paginator, problem::*, *};
4+
use crate::entity::{contest, problem::Paginator, problem::*};
55

66
impl<'a> From<WithAuth<'a, Model>> for ProblemFullInfo {
77
fn from(value: WithAuth<'a, Model>) -> Self {

backend/src/endpoint/submit.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
1-
use super::tools::*;
1+
use super::*;
22

33
use crate::controller::judger::SubmitBuilder;
44
use crate::util::code::Code;
5-
use grpc::backend::submit_server::*;
6-
use grpc::backend::StateCode as BackendCode;
5+
use grpc::backend::{submit_server::*, StateCode as BackendCode};
76

87
use crate::entity::{
8+
contest, problem, submit,
99
submit::{Paginator, *},
10-
*,
10+
user,
1111
};
1212
use tokio_stream::wrappers::ReceiverStream;
1313

backend/src/endpoint/testcase.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
use super::tools::*;
1+
use super::*;
22

33
use grpc::backend::testcase_server::*;
44

55
use crate::entity::{
6+
problem,
67
testcase::{Paginator, *},
7-
*,
88
};
99

1010
impl<'a> From<WithAuth<'a, Model>> for TestcaseFullInfo {
@@ -118,7 +118,6 @@ impl Testcase for ArcServer {
118118
)]
119119
async fn update(&self, req: Request<UpdateTestcaseRequest>) -> Result<Response<()>, Status> {
120120
let (auth, req) = self.rate_limit(req).in_current_span().await?;
121-
let (_, perm) = auth.assume_login()?;
122121
req.bound_check()?;
123122

124123
req.get_or_insert(|req| async move {

backend/src/endpoint/token.rs

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,12 @@
11
use std::num::NonZeroU32;
22
use std::time::Duration;
33

4-
use super::tools::*;
4+
use super::*;
55

66
use grpc::backend::token_server::*;
77

88
use crate::entity::token::*;
9-
use crate::entity::*;
10-
use crate::util::rate_limit::RateLimit;
9+
use crate::{entity::user, util::rate_limit::RateLimit};
1110

1211
const TOKEN_LIMIT: u64 = 16;
1312

@@ -73,7 +72,7 @@ impl Token for ArcServer {
7372
if self.crypto.hash_eq(req.password.as_str(), &model.password) {
7473
let dur =
7574
chrono::Duration::from_std(Duration::from_secs(req.expiry.unwrap_or(60 * 60 * 12)))
76-
.map_err(|err| Error::BadArgument("expiry"))?;
75+
.map_err(|_| Error::BadArgument("expiry"))?;
7776
let (token, expiry) = self.token.add(&model, dur).in_current_span().await?;
7877

7978
Ok(Response::new(TokenInfo {
@@ -93,7 +92,7 @@ impl Token for ArcServer {
9392
err(level = "debug", Display)
9493
)]
9594
async fn refresh(&self, req: Request<RefreshRequest>) -> Result<Response<TokenInfo>, Status> {
96-
let (auth, bucket) = self.parse_auth(&req).in_current_span().await?;
95+
let (_, bucket) = self.parse_auth(&req).in_current_span().await?;
9796
let (meta, _, req) = req.into_parts();
9897
bucket.cost(NonZeroU32::new(req.get_cost()).unwrap())?;
9998

@@ -112,7 +111,7 @@ impl Token for ArcServer {
112111
let dur = chrono::Duration::from_std(Duration::from_secs(
113112
req.expiry.unwrap_or(60 * 60 * 12),
114113
))
115-
.map_err(|err| Error::BadArgument("expiry"))?;
114+
.map_err(|_| Error::BadArgument("expiry"))?;
116115

117116
self.token.remove(token.to_string()).await?;
118117
let (token, expiry) = self.token.add(&user, dur).in_current_span().await?;

backend/src/endpoint/user.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use super::tools::*;
1+
use super::*;
22

33
use grpc::backend::user_server::*;
44

@@ -97,7 +97,7 @@ impl User for ArcServer {
9797
let (auth, req) = self.rate_limit(req).in_current_span().await?;
9898
req.bound_check()?;
9999

100-
let (user_id, perm) = auth.assume_login()?;
100+
let perm = auth.perm();
101101
perm.super_user()?;
102102

103103
req.get_or_insert(|req| async move {
@@ -151,7 +151,7 @@ impl User for ArcServer {
151151
let (auth, req) = self.rate_limit(req).in_current_span().await?;
152152
req.bound_check()?;
153153

154-
let (user_id, perm) = auth.assume_login()?;
154+
let perm = auth.perm();
155155
perm.admin()?;
156156

157157
req.get_or_insert(|req| async move {

backend/src/endpoint/util.rs

Lines changed: 0 additions & 1 deletion
This file was deleted.

backend/src/entity/announcement.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
use super::*;
22
use grpc::backend::list_announcement_request::Sort;
33

4-
pub static NAME: &str = "announcement";
5-
64
#[derive(Clone, Debug, PartialEq, DeriveEntityModel, Eq)]
75
#[sea_orm(table_name = "announcement")]
86
pub struct Model {

0 commit comments

Comments
 (0)