Skip to content

Commit

Permalink
fix(Backend): 🐛 fix mismatched Code
Browse files Browse the repository at this point in the history
  • Loading branch information
Eason0729 committed Feb 4, 2024
1 parent 743b51e commit d02eca3
Show file tree
Hide file tree
Showing 12 changed files with 51 additions and 88 deletions.
2 changes: 1 addition & 1 deletion backend/src/controller/code.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use crate::grpc::backend::StateCode as BackendCode;
use crate::grpc::judger::JudgerCode;

/// Stablized JudgeResponse Code, store in database
#[derive(Clone, Copy,PartialEq, Eq)]
#[derive(Clone, Copy, PartialEq, Eq)]
#[repr(C)]
pub enum Code {
Accepted = 1,
Expand Down
21 changes: 8 additions & 13 deletions backend/src/controller/judger/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ use std::{
use tokio_stream::StreamExt;

use crate::{
grpc::TonicStream,
grpc::{backend::StateCode as BackendCode, TonicStream},
init::{config, logger::PACKAGE_NAME},
report_internal,
};
Expand All @@ -26,7 +26,7 @@ use tracing::{instrument, Instrument, Span};
use uuid::Uuid;

use crate::grpc::{
backend::{submit_status, JudgeResult as BackendResult, PlaygroundResult, SubmitStatus},
backend::{submit_status, PlaygroundResult, SubmitStatus},
judger::{JudgeResponse, *},
};

Expand Down Expand Up @@ -131,7 +131,7 @@ impl From<Code> for SubmitStatus {
fn from(value: Code) -> Self {
SubmitStatus {
task: Some(submit_status::Task::Result(
Into::<Code>::into(value) as i32
Into::<BackendCode>::into(value) as i32,
)),
}
}
Expand Down Expand Up @@ -240,7 +240,7 @@ impl JudgerController {
if ps_guard
.send(Ok(SubmitStatus {
task: Some(submit_status::Task::Result(
Into::<Code>::into(status) as i32
Into::<BackendCode>::into(status) as i32,
)),
}))
.is_err()
Expand All @@ -254,7 +254,7 @@ impl JudgerController {
model.pass_case = ActiveValue::Set(pass_case);
model.time = ActiveValue::Set(Some(total_time.try_into().unwrap_or(i64::MAX)));
model.memory = ActiveValue::Set(Some(total_memory.try_into().unwrap_or(i64::MAX)));
model.accept=ActiveValue::Set(status==Code::Accepted);
model.accept = ActiveValue::Set(status == Code::Accepted);

drop(meter);

Expand Down Expand Up @@ -324,14 +324,9 @@ impl JudgerController {
.await
{
Ok(submit) => {
score::ScoreUpload::new(
req.user,
problem,
submit.score,
submit.accept,
)
.upload(&db)
.await;
score::ScoreUpload::new(req.user, problem, submit.score, submit.accept)
.upload(&db)
.await;
}
Err(err) => {
tracing::warn!(err = err.to_string(), "judge_fail");
Expand Down
20 changes: 7 additions & 13 deletions backend/src/endpoint/announcement.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ impl AnnouncementSet for Arc<Server> {
) -> Result<Response<ListAnnouncementResponse>, Status> {
let (auth, req) = self.parse_request(req).await?;

let (rev,size)=split_rev(req.size);
let (rev, size) = split_rev(req.size);
let size = bound!(size, 64);
let offset = bound!(req.offset(), 1024);

Expand All @@ -83,9 +83,7 @@ impl AnnouncementSet for Arc<Server> {
}
list_announcement_request::Request::Pager(old) => {
let pager: ColPaginator = self.crypto.decode(old.session)?;
pager
.fetch(&auth, size, offset, rev, &self.db)
.await
pager.fetch(&auth, size, offset, rev, &self.db).await
}
}?;

Expand All @@ -103,8 +101,8 @@ impl AnnouncementSet for Arc<Server> {
req: Request<TextSearchRequest>,
) -> Result<Response<ListAnnouncementResponse>, Status> {
let (auth, req) = self.parse_request(req).await?;
let (rev,size)=split_rev(req.size);

let (rev, size) = split_rev(req.size);
let size = bound!(size, 64);
let offset = bound!(req.offset(), 1024);

Expand All @@ -114,9 +112,7 @@ impl AnnouncementSet for Arc<Server> {
}
text_search_request::Request::Pager(old) => {
let pager: TextPaginator = self.crypto.decode(old.session)?;
pager
.fetch(&auth, size, offset, rev, &self.db)
.await
pager.fetch(&auth, size, offset, rev, &self.db).await
}
}?;

Expand Down Expand Up @@ -381,7 +377,7 @@ impl AnnouncementSet for Arc<Server> {
req: Request<ListByRequest>,
) -> Result<Response<ListAnnouncementResponse>, Status> {
let (auth, req) = self.parse_request(req).await?;
let (rev,size)=split_rev(req.size);
let (rev, size) = split_rev(req.size);
let size = bound!(size, 64);
let offset = bound!(req.offset(), 1024);

Expand All @@ -400,9 +396,7 @@ impl AnnouncementSet for Arc<Server> {
}
list_by_request::Request::Pager(old) => {
let pager: ParentPaginator = self.crypto.decode(old.session)?;
pager
.fetch(&auth, size, offset, rev, &self.db)
.await
pager.fetch(&auth, size, offset, rev, &self.db).await
}
}?;

Expand Down
8 changes: 3 additions & 5 deletions backend/src/endpoint/chat.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,8 @@ impl ChatSet for Arc<Server> {
req: Request<ListByRequest>,
) -> Result<Response<ListChatResponse>, Status> {
let (auth, req) = self.parse_request(req).await?;
let (rev,size)=split_rev(req.size);

let (rev, size) = split_rev(req.size);
let size = bound!(size, 64);
let offset = bound!(req.offset(), 1024);

Expand All @@ -104,9 +104,7 @@ impl ChatSet for Arc<Server> {
}
list_by_request::Request::Pager(old) => {
let pager: ParentPaginator = self.crypto.decode(old.session)?;
pager
.fetch(&auth, size, offset, rev, &self.db)
.await
pager.fetch(&auth, size, offset, rev, &self.db).await
}
}?;

Expand Down
14 changes: 5 additions & 9 deletions backend/src/endpoint/contest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ impl ContestSet for Arc<Server> {
) -> Result<Response<ListContestResponse>, Status> {
let (auth, req) = self.parse_request(req).await?;

let (rev,size)=split_rev(req.size);
let (rev, size) = split_rev(req.size);
let size = bound!(size, 64);
let offset = bound!(req.offset(), 1024);

Expand All @@ -88,9 +88,7 @@ impl ContestSet for Arc<Server> {
}
list_contest_request::Request::Pager(old) => {
let pager: ColPaginator = self.crypto.decode(old.session)?;
pager
.fetch(&auth, size, offset, rev, &self.db)
.await
pager.fetch(&auth, size, offset, rev, &self.db).await
}
}?;

Expand All @@ -105,8 +103,8 @@ impl ContestSet for Arc<Server> {
req: Request<TextSearchRequest>,
) -> Result<Response<ListContestResponse>, Status> {
let (auth, req) = self.parse_request(req).await?;
let (rev,size)=split_rev(req.size);

let (rev, size) = split_rev(req.size);
let size = bound!(size, 64);
let offset = bound!(req.offset(), 1024);

Expand All @@ -116,9 +114,7 @@ impl ContestSet for Arc<Server> {
}
text_search_request::Request::Pager(old) => {
let pager: TextPaginator = self.crypto.decode(old.session)?;
pager
.fetch(&auth, size, offset, rev, &self.db)
.await
pager.fetch(&auth, size, offset, rev, &self.db).await
}
}?;

Expand Down
10 changes: 4 additions & 6 deletions backend/src/endpoint/education.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ impl EducationSet for Arc<Server> {
) -> Result<Response<ListEducationResponse>, Status> {
let (auth, req) = self.parse_request(req).await?;

let (rev,size)=split_rev(req.size);
let (rev, size) = split_rev(req.size);
let size = bound!(size, 64);
let offset = bound!(req.offset(), 1024);

Expand Down Expand Up @@ -219,8 +219,8 @@ impl EducationSet for Arc<Server> {
req: Request<ListByRequest>,
) -> Result<Response<ListEducationResponse>, Status> {
let (auth, req) = self.parse_request(req).await?;
let (rev,size)=split_rev(req.size);

let (rev, size) = split_rev(req.size);
let size = bound!(size, 64);
let offset = bound!(req.offset(), 1024);

Expand All @@ -239,9 +239,7 @@ impl EducationSet for Arc<Server> {
}
list_by_request::Request::Pager(old) => {
let pager: ParentPaginator = self.crypto.decode(old.session)?;
pager
.fetch(&auth, size, offset, rev, &self.db)
.await
pager.fetch(&auth, size, offset, rev, &self.db).await
}
}?;

Expand Down
4 changes: 2 additions & 2 deletions backend/src/endpoint/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ mod tools {
pub use tonic::*;
pub use tracing::instrument;
pub use uuid::Uuid;
pub fn split_rev(raw:i64)->(bool,u64){
return (raw <0,raw.abs().try_into().unwrap());
pub fn split_rev(raw: i64) -> (bool, u64) {
return (raw < 0, raw.abs().try_into().unwrap());
}
}
20 changes: 7 additions & 13 deletions backend/src/endpoint/problem.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ impl ProblemSet for Arc<Server> {
) -> Result<Response<ListProblemResponse>, Status> {
let (auth, req) = self.parse_request(req).await?;

let (rev,size)=split_rev(req.size);
let (rev, size) = split_rev(req.size);
let size = bound!(size, 64);
let offset = bound!(req.offset(), 1024);

Expand All @@ -75,9 +75,7 @@ impl ProblemSet for Arc<Server> {
}
list_problem_request::Request::Pager(old) => {
let pager: ColPaginator = self.crypto.decode(old.session)?;
pager
.fetch(&auth, size, offset, rev, &self.db)
.await
pager.fetch(&auth, size, offset, rev, &self.db).await
}
}?;

Expand All @@ -93,7 +91,7 @@ impl ProblemSet for Arc<Server> {
) -> Result<Response<ListProblemResponse>, Status> {
let (auth, req) = self.parse_request(req).await?;

let (rev,size)=split_rev(req.size);
let (rev, size) = split_rev(req.size);
let size = bound!(size, 64);
let offset = bound!(req.offset(), 1024);

Expand All @@ -103,9 +101,7 @@ impl ProblemSet for Arc<Server> {
}
text_search_request::Request::Pager(old) => {
let pager: TextPaginator = self.crypto.decode(old.session)?;
pager
.fetch(&auth, size, offset, rev, &self.db)
.await
pager.fetch(&auth, size, offset, rev, &self.db).await
}
}?;

Expand Down Expand Up @@ -374,10 +370,10 @@ impl ProblemSet for Arc<Server> {
) -> Result<Response<ListProblemResponse>, Status> {
let (auth, req) = self.parse_request(req).await?;

let (rev,size)=split_rev(req.size);
let (rev, size) = split_rev(req.size);
let size = bound!(size, 64);
let offset = bound!(req.offset(), 1024);

let (pager, models) = match req.request.ok_or(Error::NotInPayload("request"))? {
list_by_request::Request::Create(create) => {
tracing::debug!(id = create.parent_id);
Expand All @@ -393,9 +389,7 @@ impl ProblemSet for Arc<Server> {
}
list_by_request::Request::Pager(old) => {
let pager: ParentPaginator = self.crypto.decode(old.session)?;
pager
.fetch(&auth, size, offset, rev, &self.db)
.await
pager.fetch(&auth, size, offset, rev, &self.db).await
}
}?;

Expand Down
12 changes: 4 additions & 8 deletions backend/src/endpoint/submit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ impl SubmitSet for Arc<Server> {
) -> Result<Response<ListSubmitResponse>, Status> {
let (auth, req) = self.parse_request(req).await?;

let (rev,size)=split_rev(req.size);
let (rev, size) = split_rev(req.size);
let size = bound!(size, 64);
let offset = bound!(req.offset(), 1024);

Expand All @@ -81,9 +81,7 @@ impl SubmitSet for Arc<Server> {
}
list_submit_request::Request::Pager(old) => {
let pager: ColPaginator = self.crypto.decode(old.session)?;
pager
.fetch(&auth, size, offset, rev, &self.db)
.await
pager.fetch(&auth, size, offset, rev, &self.db).await
}
}?;

Expand All @@ -100,7 +98,7 @@ impl SubmitSet for Arc<Server> {
) -> Result<Response<ListSubmitResponse>, Status> {
let (auth, req) = self.parse_request(req).await?;

let (rev,size)=split_rev(req.size);
let (rev, size) = split_rev(req.size);
let size = bound!(size, 64);
let offset = bound!(req.offset(), 1024);

Expand All @@ -118,9 +116,7 @@ impl SubmitSet for Arc<Server> {
}
list_by_request::Request::Pager(old) => {
let pager: ParentPaginator = self.crypto.decode(old.session)?;
pager
.fetch(&auth, size, offset, rev, &self.db)
.await
pager.fetch(&auth, size, offset, rev, &self.db).await
}
}?;

Expand Down
12 changes: 4 additions & 8 deletions backend/src/endpoint/testcase.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,16 +45,14 @@ impl TestcaseSet for Arc<Server> {
) -> Result<Response<ListTestcaseResponse>, Status> {
let (auth, req) = self.parse_request(req).await?;

let (rev,size)=split_rev(req.size);
let (rev, size) = split_rev(req.size);
let size = bound!(size, 64);
let offset = bound!(req.offset(), 1024);

let (pager, models) = match req.request.ok_or(Error::NotInPayload("request"))? {
list_testcase_request::Request::Pager(old) => {
let pager: ColPaginator = self.crypto.decode(old.session)?;
pager
.fetch(&auth, size, offset, rev, &self.db)
.await
pager.fetch(&auth, size, offset, rev, &self.db).await
}
list_testcase_request::Request::StartFromEnd(rev) => {
ColPaginator::new_fetch(Default::default(), &auth, size, offset, rev, &self.db)
Expand Down Expand Up @@ -253,7 +251,7 @@ impl TestcaseSet for Arc<Server> {
) -> Result<Response<ListTestcaseResponse>, Status> {
let (auth, req) = self.parse_request(req).await?;

let (rev,size)=split_rev(req.size);
let (rev, size) = split_rev(req.size);
let size = bound!(size, 64);
let offset = bound!(req.offset(), 1024);

Expand All @@ -271,9 +269,7 @@ impl TestcaseSet for Arc<Server> {
}
list_by_request::Request::Pager(old) => {
let pager: ParentPaginator = self.crypto.decode(old.session)?;
pager
.fetch(&auth, size, offset, rev, &self.db)
.await
pager.fetch(&auth, size, offset, rev, &self.db).await
}
}?;

Expand Down
Loading

0 comments on commit d02eca3

Please sign in to comment.