This repository has been archived by the owner on Sep 21, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 37
feat: Introduce "--storage-memory-cache-limit" #671
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,4 +14,4 @@ | |
"test-kubo", | ||
"helpers" | ||
] | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,11 +11,7 @@ pub mod workspace; | |
#[cfg(any(test, feature = "helpers"))] | ||
pub mod helpers; | ||
|
||
use anyhow::Result; | ||
|
||
use noosphere_core::tracing::initialize_tracing; | ||
|
||
use clap::Parser; | ||
use std::path::{Path, PathBuf}; | ||
|
||
use self::{ | ||
cli::{AuthCommand, Cli, ConfigCommand, FollowCommand, KeyCommand, OrbCommand, SphereCommand}, | ||
|
@@ -29,24 +25,61 @@ use self::{ | |
}, | ||
workspace::Workspace, | ||
}; | ||
use anyhow::Result; | ||
use clap::Parser; | ||
use noosphere_core::tracing::initialize_tracing; | ||
use noosphere_storage::StorageConfig; | ||
|
||
/// Additional context used to invoke a [Cli] command. | ||
pub struct CliContext<'a> { | ||
/// Path to the current working directory. | ||
cwd: PathBuf, | ||
/// Path to the global configuration directory, if provided. | ||
global_config_directory: Option<&'a Path>, | ||
} | ||
|
||
#[cfg(not(doc))] | ||
#[allow(missing_docs)] | ||
pub async fn main() -> Result<()> { | ||
initialize_tracing(None); | ||
let context = CliContext { | ||
cwd: std::env::current_dir()?, | ||
global_config_directory: None, | ||
}; | ||
invoke_cli(Cli::parse(), &context).await | ||
} | ||
|
||
let workspace = Workspace::new(&std::env::current_dir()?, None)?; | ||
/// Invoke the CLI implementation imperatively. | ||
/// | ||
/// This is the entrypoint used by orb when handling a command line invocation. | ||
/// The [Cli] is produced by parsing the command line arguments, and internally | ||
/// creates a new [Workspace] from the current working directory. | ||
/// | ||
/// Use [invoke_cli_with_workspace] if using your own [Workspace]. | ||
pub async fn invoke_cli<'a>(cli: Cli, context: &CliContext<'a>) -> Result<()> { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
let storage_config = if let OrbCommand::Serve { | ||
storage_memory_cache_limit, | ||
.. | ||
} = &cli.command | ||
{ | ||
Some(StorageConfig { | ||
memory_cache_limit: *storage_memory_cache_limit, | ||
}) | ||
} else { | ||
None | ||
}; | ||
let workspace = Workspace::new( | ||
&context.cwd, | ||
context.global_config_directory, | ||
storage_config, | ||
)?; | ||
|
||
invoke_cli(Cli::parse(), workspace).await | ||
invoke_cli_with_workspace(cli, workspace).await | ||
} | ||
|
||
/// Invoke the CLI implementation imperatively. This is the entrypoint used by | ||
/// orb when handling a command line invocation. The [Cli] is produced by | ||
/// parsing the command line arguments, and the [Workspace] is initialized from | ||
/// the current working directory. The effect of invoking the CLI this way will | ||
/// depend on the [Cli] and [Workspace] provided (results may vary significantly | ||
/// depending on those inputs). | ||
pub async fn invoke_cli(cli: Cli, mut workspace: Workspace) -> Result<()> { | ||
/// Same as [invoke_cli], but enables the caller to provide their own | ||
/// initialized [Workspace] | ||
pub async fn invoke_cli_with_workspace(cli: Cli, mut workspace: Workspace) -> Result<()> { | ||
match cli.command { | ||
OrbCommand::Key { command } => match command { | ||
KeyCommand::Create { name } => key_create(&name, &workspace).await?, | ||
|
@@ -117,18 +150,19 @@ pub async fn invoke_cli(cli: Cli, mut workspace: Workspace) -> Result<()> { | |
name_resolver_api, | ||
interface, | ||
port, | ||
.. | ||
} => { | ||
serve( | ||
interface, | ||
port, | ||
ipfs_api, | ||
name_resolver_api, | ||
cors_origin, | ||
&workspace, | ||
&mut workspace, | ||
) | ||
.await? | ||
.await?; | ||
} | ||
}; | ||
} | ||
|
||
Ok(()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
use crate::storage::Storage; | ||
use anyhow::Result; | ||
use async_trait::async_trait; | ||
use noosphere_common::ConditionalSend; | ||
use std::path::Path; | ||
|
||
/// Generalized configurations for [ConfigurableStorage]. | ||
#[derive(Debug, Clone, Default)] | ||
pub struct StorageConfig { | ||
/// If set, the size limit in bytes of a memory-based cache. | ||
pub memory_cache_limit: Option<usize>, | ||
} | ||
|
||
/// [Storage] that can be customized via [StorageConfig]. | ||
/// | ||
/// Configurations are generalized across storage providers, | ||
/// and may have differing underlying semantics. | ||
#[cfg_attr(not(target_arch = "wasm32"), async_trait)] | ||
#[cfg_attr(target_arch = "wasm32", async_trait(?Send))] | ||
pub trait ConfigurableStorage: Storage { | ||
async fn open_with_config<P: AsRef<Path> + ConditionalSend>( | ||
path: P, | ||
config: StorageConfig, | ||
) -> Result<Self>; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we get a short arg for this? e.g.,
short = 'S'
or somethingThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Punting on this for now, as this is a low-level operator command