Skip to content

Commit

Permalink
Clean up
Browse files Browse the repository at this point in the history
  • Loading branch information
nicholaslyang authored and nicholaslyang committed Jul 31, 2023
1 parent 8448e05 commit 6bca618
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 16 deletions.
4 changes: 2 additions & 2 deletions crates/turborepo-api-client/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ pub struct PreflightResponse {
}

#[derive(Deserialize)]
struct ApiError {
struct APIError {
code: String,
message: String,
}
Expand Down Expand Up @@ -334,7 +334,7 @@ impl APIClient {
}

async fn handle_403(response: Response) -> Error {
let api_error: ApiError = match response.json().await {
let api_error: APIError = match response.json().await {
Ok(api_error) => api_error,
Err(e) => return Error::ReqwestError(e),
};
Expand Down
4 changes: 3 additions & 1 deletion crates/turborepo-cache/src/async_cache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,9 @@ impl AsyncCache {
self.real_cache.exists(key, team_id, team_slug).await
}

// Mostly used for testing to ensure that the workers resolve
// Used for testing to ensure that the workers resolve
// before checking the cache.
#[cfg(test)]
pub async fn wait(&mut self) {
while let Some(worker) = self.workers.next().await {
let _ = worker;
Expand Down
8 changes: 4 additions & 4 deletions crates/turborepo-cache/src/fs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use crate::{
CacheError, CacheResponse, CacheSource,
};

pub struct FsCache {
pub struct FSCache {
cache_directory: AbsoluteSystemPathBuf,
}

Expand All @@ -26,7 +26,7 @@ impl CacheMetadata {
}
}

impl FsCache {
impl FSCache {
fn resolve_cache_dir(
repo_root: &AbsoluteSystemPath,
override_dir: Option<&Utf8Path>,
Expand All @@ -45,7 +45,7 @@ impl FsCache {
let cache_directory = Self::resolve_cache_dir(repo_root, override_dir);
cache_directory.create_dir_all()?;

Ok(FsCache { cache_directory })
Ok(FSCache { cache_directory })
}

pub fn fetch(
Expand Down Expand Up @@ -174,7 +174,7 @@ mod test {
let repo_root_path = AbsoluteSystemPath::from_std_path(repo_root.path())?;
test_case.initialize(repo_root_path)?;

let cache = FsCache::new(None, &repo_root_path)?;
let cache = FSCache::new(None, &repo_root_path)?;

let expected_miss = cache
.exists(&test_case.hash)
Expand Down
14 changes: 5 additions & 9 deletions crates/turborepo-cache/src/multiplexer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,18 @@ use turbopath::{AbsoluteSystemPath, AnchoredSystemPathBuf};
use turborepo_api_client::APIClient;

use crate::{
fs::FsCache,
fs::FSCache,
http::{APIAuth, HTTPCache},
CacheError, CacheOpts, CacheResponse,
};

pub struct CacheMultiplexer {
// We use an `AtomicBool` instead of removing the cache because that would require
// wrapping the cache in a Mutex which would cause a lot of contention.
// wrapping the cache in a `Mutex` which would cause a lot of contention.
// This does create a mild race condition where we might use the cache
// even though another thread might be removing it, but that's fine.
should_use_http_cache: AtomicBool,
fs: Option<FsCache>,
fs: Option<FSCache>,
http: Option<HTTPCache>,
}

Expand All @@ -29,20 +29,16 @@ impl CacheMultiplexer {
) -> Result<Self, CacheError> {
let use_fs_cache = !opts.skip_filesystem;
let use_http_cache = !opts.skip_remote;

// Since the above two flags are not mutually exclusive it is possible to
// configure yourself out of having a cache. We should tell you about it
// but we shouldn't fail your build for that reason.
//
// Further, since the httpCache can be removed at runtime, we need to insert a
// noopCache as a backup if you are configured to have *just* an
// httpCache.
//
if !use_fs_cache && !use_http_cache {
warn!("no caches are enabled");
}

let fs_cache = use_fs_cache
.then(|| FsCache::new(opts.override_dir, repo_root))
.then(|| FSCache::new(opts.override_dir, repo_root))
.transpose()?;

let http_cache = use_http_cache
Expand Down

0 comments on commit 6bca618

Please sign in to comment.