Skip to content

Commit 1658ef6

Browse files
authored
refactor orion-server (#2034)
1 parent eabfab1 commit 1658ef6

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+2840
-3590
lines changed

api-model/src/buck2/api.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ use utoipa::ToSchema;
1414
use crate::buck2::{status::Status, types::ProjectRelativePath};
1515

1616
/// Parameters required to build a task.
17-
#[allow(dead_code)]
1817
#[derive(Debug, Deserialize, Serialize, ToSchema)]
1918
pub struct TaskBuildRequest {
2019
/// The repository base path
@@ -47,7 +46,6 @@ pub struct RetryBuildRequest {
4746
}
4847

4948
/// Result of a task build operation containing status and metadata. Used by Orion-Server
50-
#[allow(dead_code)]
5149
#[derive(Debug, Deserialize, Serialize, ToSchema)]
5250
pub struct OrionBuildResult {
5351
/// Unique identifier for the build task

api-model/src/buck2/types.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ use serde::{Deserialize, Serialize};
55
use utoipa::ToSchema;
66

77
/// Task phase when in buck2 build
8-
#[allow(dead_code)]
98
#[derive(Debug, Clone, Serialize, Deserialize, ToSchema, PartialEq, Eq)]
109
pub enum TaskPhase {
1110
DownloadingSource,

api-model/src/buck2/ws.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ use crate::buck2::{
88
};
99

1010
/// Message protocol for WebSocket communication between worker and server.
11-
#[allow(dead_code)]
1211
#[derive(Debug, Serialize, Deserialize, Clone)]
1312
#[serde(tag = "type")]
1413
pub enum WSMessage {

ceres/src/model/change_list.rs

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -302,7 +302,7 @@ pub enum RequirementsState {
302302
}
303303

304304
#[derive(Debug, Clone, serde::Deserialize, serde::Serialize, utoipa::ToSchema)]
305-
#[allow(dead_code)]
305+
306306
pub struct VerifyClPayload {
307307
pub assignees: Vec<String>,
308308
}
@@ -386,12 +386,6 @@ impl ClDiffFile {
386386
}
387387
}
388388
}
389-
#[derive(Serialize)]
390-
pub struct BuckFile {
391-
pub buck: ObjectHash,
392-
pub buck_config: ObjectHash,
393-
pub path: PathBuf,
394-
}
395389

396390
#[cfg(test)]
397391
mod tests {

ceres/src/pack/monorepo.rs

Lines changed: 3 additions & 122 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use std::{
22
collections::{HashMap, HashSet},
3-
path::{Component, Path, PathBuf},
3+
path::{Component, PathBuf},
44
str::FromStr,
55
sync::{
66
Arc,
@@ -39,9 +39,9 @@ use tokio::sync::{RwLock, mpsc};
3939
use tokio_stream::wrappers::ReceiverStream;
4040

4141
use crate::{
42-
api_service::{ApiHandler, cache::GitObjectCache, mono_api_service::MonoApiService, tree_ops},
42+
api_service::{ApiHandler, cache::GitObjectCache, mono_api_service::MonoApiService},
4343
code_edit::{on_push::OnpushCodeEdit, utils::get_changed_files},
44-
model::change_list::{BuckFile, ClDiffFile},
44+
model::change_list::ClDiffFile,
4545
pack::RepoHandler,
4646
protocol::import_refs::{RefCommand, Refs},
4747
};
@@ -589,93 +589,6 @@ impl MonoRepo {
589589
Ok(cl_link)
590590
}
591591

592-
#[allow(dead_code)]
593-
async fn search_buck_under_cl(&self, cl_path: &Path) -> Result<Vec<BuckFile>, MegaError> {
594-
let mut res = vec![];
595-
let mono_stg = self.storage.mono_storage();
596-
let mono_api_service: MonoApiService = self.into();
597-
598-
let mut path = Some(cl_path);
599-
let mut path_q = Vec::new();
600-
while let Some(p) = path {
601-
path_q.push(p);
602-
path = p.parent();
603-
}
604-
if path_q.len() > 2 {
605-
path_q.pop();
606-
path_q.pop();
607-
608-
let p = path_q[path_q.len() - 1];
609-
if p.parent().is_some()
610-
&& let Some(tree) = tree_ops::search_tree_by_path(&mono_api_service, p, None)
611-
.await
612-
.ok()
613-
.flatten()
614-
&& let Some(buck) = self.try_extract_buck(tree, cl_path)
615-
{
616-
return Ok(vec![buck]);
617-
};
618-
return Ok(vec![]);
619-
}
620-
621-
let mut search_trees: Vec<(PathBuf, Tree)> = vec![];
622-
623-
let diff_trees = self.diff_trees_from_cl().await?;
624-
for (path, new, old) in diff_trees {
625-
match (new, old) {
626-
(None, _) => {
627-
continue;
628-
}
629-
(Some(sha1), _) => {
630-
let tree = mono_stg.get_tree_by_hash(&sha1.to_string()).await?.unwrap();
631-
search_trees.push((path, Tree::from_mega_model(tree)));
632-
}
633-
}
634-
}
635-
636-
for (path, tree) in search_trees {
637-
if let Some(buck) = self.try_extract_buck(tree, &cl_path.join(path)) {
638-
res.push(buck);
639-
}
640-
}
641-
642-
Ok(res)
643-
}
644-
645-
fn try_extract_buck(&self, tree: Tree, cl_path: &Path) -> Option<BuckFile> {
646-
let mut buck = None;
647-
let mut buck_config = None;
648-
for item in tree.tree_items {
649-
if item.is_blob() && item.name == "BUCK" {
650-
buck = Some(item.id)
651-
}
652-
if item.is_blob() && item.name == ".buckconfig" {
653-
buck_config = Some(item.id)
654-
}
655-
}
656-
match (buck, buck_config) {
657-
(Some(buck), Some(buck_config)) => Some(BuckFile {
658-
buck,
659-
buck_config,
660-
path: cl_path.to_path_buf(),
661-
}),
662-
_ => None,
663-
}
664-
}
665-
666-
async fn diff_trees_from_cl(
667-
&self,
668-
) -> Result<Vec<(PathBuf, Option<ObjectHash>, Option<ObjectHash>)>, MegaError> {
669-
let mono_stg = self.storage.mono_storage();
670-
let from_c = mono_stg.get_commit_by_hash(&self.from_hash).await?.unwrap();
671-
let from_tree: Tree =
672-
Tree::from_mega_model(mono_stg.get_tree_by_hash(&from_c.tree).await?.unwrap());
673-
let to_c = mono_stg.get_commit_by_hash(&self.to_hash).await?.unwrap();
674-
let to_tree: Tree =
675-
Tree::from_mega_model(mono_stg.get_tree_by_hash(&to_c.tree).await?.unwrap());
676-
diff_trees(&to_tree, &from_tree)
677-
}
678-
679592
pub fn username(&self) -> String {
680593
self.username.clone().unwrap_or(String::from("Anonymous"))
681594
}
@@ -841,35 +754,3 @@ impl MonoRepo {
841754
Ok(())
842755
}
843756
}
844-
845-
#[allow(dead_code)]
846-
type DiffResult = Vec<(PathBuf, Option<ObjectHash>, Option<ObjectHash>)>;
847-
848-
#[allow(dead_code)]
849-
fn diff_trees(theirs: &Tree, base: &Tree) -> Result<DiffResult, MegaError> {
850-
let their_items: HashMap<_, _> = get_plain_items(theirs).into_iter().collect();
851-
let base_items: HashMap<_, _> = get_plain_items(base).into_iter().collect();
852-
let all_paths: HashSet<_> = their_items.keys().chain(base_items.keys()).collect();
853-
854-
let mut diffs = Vec::new();
855-
856-
for path in all_paths {
857-
let their_hash = their_items.get(path).cloned();
858-
let base_hash = base_items.get(path).cloned();
859-
if their_hash != base_hash {
860-
diffs.push((path.clone(), their_hash, base_hash));
861-
}
862-
}
863-
Ok(diffs)
864-
}
865-
866-
#[allow(dead_code)]
867-
fn get_plain_items(tree: &Tree) -> Vec<(PathBuf, ObjectHash)> {
868-
let mut items = Vec::new();
869-
for item in tree.tree_items.iter() {
870-
if item.is_tree() {
871-
items.push((PathBuf::from(item.name.clone()), item.id));
872-
}
873-
}
874-
items
875-
}

io-orbit/src/bin/migrate_local_to_s3.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -290,11 +290,11 @@ async fn migrate_all(
290290
// Periodically await some tasks to keep the number of in-memory
291291
// JoinHandles bounded. Semaphore still enforces the true I/O
292292
// concurrency; this only caps bookkeeping overhead.
293-
if tasks.len() >= concurrency.saturating_mul(4).max(64) {
294-
if let Some(t) = tasks.pop() {
295-
t.await
296-
.map_err(|e| MegaError::Other(format!("migration task panicked: {e}")))??;
297-
}
293+
if tasks.len() >= concurrency.saturating_mul(4).max(64)
294+
&& let Some(t) = tasks.pop()
295+
{
296+
t.await
297+
.map_err(|e| MegaError::Other(format!("migration task panicked: {e}")))??;
298298
}
299299
}
300300

mono/src/api/guard/cedar_guard.rs

Lines changed: 1 addition & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use std::{collections::HashMap, path::Path, str::FromStr};
1+
use std::{collections::HashMap, str::FromStr};
22

33
use axum::{
44
extract::{FromRef, FromRequestParts, Request, State},
@@ -216,27 +216,6 @@ async fn authorize(
216216
Ok(())
217217
}
218218

219-
#[allow(dead_code)]
220-
async fn get_blob_string(state: &MonoApiServiceState, path: &Path) -> Result<String, ApiError> {
221-
// Use main as default branch
222-
let refs = None;
223-
let data = state
224-
.api_handler(path.as_ref())
225-
.await?
226-
.get_blob_as_string(path.into(), refs)
227-
.await?;
228-
229-
match data {
230-
Some(content) => Ok(content),
231-
None => {
232-
Err(MegaError::Other(format!(
233-
"Blob not found at path: {}",
234-
path.display()
235-
)))
236-
}?,
237-
}
238-
}
239-
240219
#[cfg(test)]
241220
mod tests {
242221
use super::*;

mono/src/git_protocol/ssh.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ use tokio::{io::AsyncReadExt, sync::Mutex};
2121
use crate::git_protocol::http::search_subsequence;
2222

2323
type ClientMap = HashMap<(usize, ChannelId), Channel<Msg>>;
24-
#[allow(dead_code)]
24+
2525
#[derive(Clone)]
2626
pub struct SshServer {
2727
pub clients: Arc<Mutex<ClientMap>>,

orion-server/Cargo.toml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,11 @@ path = "src/main.rs"
1313
common = { workspace = true }
1414
io-orbit = { workspace = true }
1515
api-model = { workspace = true }
16-
jupiter = { workspace = true }
1716
callisto = { workspace = true }
1817

1918
http = { workspace = true }
2019
axum = { workspace = true, features = ["macros", "ws"] }
2120
tokio = { workspace = true, features = ["rt-multi-thread", "fs", "process"] }
22-
tokio-retry = "0.3"
2321
tokio-stream = { workspace = true, features = ["sync"] }
2422
tokio-util = { workspace = true }
2523
tracing = { workspace = true }
@@ -42,7 +40,6 @@ dashmap = { workspace = true }
4240
utoipa.workspace = true
4341
utoipa-swagger-ui = { workspace = true, features = ["axum"] }
4442
chrono = { workspace = true, features = ["serde"] }
45-
reqwest.workspace = true
4643
anyhow = { workspace = true }
4744
async-trait = { workspace = true }
4845
once_cell = { workspace = true }

0 commit comments

Comments
 (0)