Skip to content

Commit

Permalink
feat: OkuNet tags
Browse files Browse the repository at this point in the history
  • Loading branch information
emmyoh committed Nov 12, 2024
1 parent f48425d commit 3fe2c76
Show file tree
Hide file tree
Showing 9 changed files with 104 additions and 65 deletions.
4 changes: 2 additions & 2 deletions .github/old-workflows/main.yml → .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ jobs:
- name: Checkout codebase
uses: actions/checkout@v4
- name: Generate documentation
run: time cargo doc --no-deps -Zrustdoc-map --release --quiet
run: time cargo doc --no-deps
- name: Fix permissions
run: |
chmod -c -R +rX "target/doc/" | while read line; do
Expand Down Expand Up @@ -60,7 +60,7 @@ jobs:
- name: Apply compiler suggestions
run: |
cargo fix --edition --edition-idioms --allow-dirty
cargo clippy --fix -Z unstable-options --allow-dirty
cargo clippy --fix --allow-dirty
- name: Commit changes to code, if any
run: |
git config user.name github-actions
Expand Down
6 changes: 1 addition & 5 deletions src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,7 @@ impl OkuFsConfig {

/// The home replica of the node.
pub fn home_replica(&self) -> miette::Result<Option<NamespaceId>> {
Ok(self
.home_replica
.try_lock()
.map_err(|e| miette!("{}", e))?
.clone())
Ok(*self.home_replica.try_lock().map_err(|e| miette!("{}", e))?)
}

/// Sets the home replica of the node.
Expand Down
30 changes: 21 additions & 9 deletions src/database.rs
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ pub struct OkuIdentity {
pub blocked: HashSet<AuthorId>,
}

#[derive(Serialize, Deserialize, PartialEq, Debug, Clone)]
#[derive(Serialize, Deserialize, Debug, Clone)]
#[native_model(id = 2, version = 1)]
#[native_db(
primary_key(primary_key -> (Vec<u8>, Vec<u8>))
Expand All @@ -132,6 +132,18 @@ pub struct OkuPost {
pub note: OkuNote,
}

impl PartialEq for OkuPost {
fn eq(&self, other: &Self) -> bool {
self.primary_key() == other.primary_key()
}
}
impl Eq for OkuPost {}
impl Hash for OkuPost {
fn hash<H: Hasher>(&self, state: &mut H) {
self.primary_key().hash(state);
}
}

impl From<OkuPost> for TantivyDocument {
fn from(value: OkuPost) -> Self {
let post_key: [Vec<u8>; 2] = value.primary_key().into();
Expand Down Expand Up @@ -276,7 +288,7 @@ impl OkuDatabase {
) -> miette::Result<Vec<OkuPost>> {
let searcher = POST_INDEX_READER.searcher();
let query_parser = QueryParser::for_index(
&*POST_INDEX,
&POST_INDEX,
vec![
POST_SCHEMA.1["author_id"],
POST_SCHEMA.1["path"],
Expand Down Expand Up @@ -422,13 +434,13 @@ impl OkuDatabase {
/// A list of all known OkuNet posts.
pub fn get_posts(&self) -> miette::Result<Vec<OkuPost>> {
let r = self.database.r_transaction().into_diagnostic()?;
Ok(r.scan()
r.scan()
.primary()
.into_diagnostic()?
.all()
.into_diagnostic()?
.collect::<Result<Vec<_>, _>>()
.into_diagnostic()?)
.into_diagnostic()
}

/// Retrieves all known OkuNet posts by a given author.
Expand Down Expand Up @@ -495,7 +507,7 @@ impl OkuDatabase {
author_id.as_bytes().to_vec(),
path_to_entry_key(path).to_vec(),
);
Ok(r.get().primary(entry_key).into_diagnostic()?)
r.get().primary(entry_key).into_diagnostic()
}

/// Insert or update an OkuNet user.
Expand Down Expand Up @@ -629,13 +641,13 @@ impl OkuDatabase {
/// The OkuNet content of all users known to this node.
pub fn get_users(&self) -> miette::Result<Vec<OkuUser>> {
let r = self.database.r_transaction().into_diagnostic()?;
Ok(r.scan()
r.scan()
.primary()
.into_diagnostic()?
.all()
.into_diagnostic()?
.collect::<Result<Vec<_>, _>>()
.into_diagnostic()?)
.into_diagnostic()
}

/// Gets an OkuNet user's content by their content authorship ID.
Expand All @@ -649,8 +661,8 @@ impl OkuDatabase {
/// An OkuNet user's content.
pub fn get_user(&self, author_id: AuthorId) -> miette::Result<Option<OkuUser>> {
let r = self.database.r_transaction().into_diagnostic()?;
Ok(r.get()
r.get()
.primary(author_id.as_bytes().to_vec())
.into_diagnostic()?)
.into_diagnostic()
}
}
6 changes: 3 additions & 3 deletions src/discovery.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ impl OkuFs {
/// * `namespace_id` - The ID of the replica to announce.
pub async fn announce_replica(&self, namespace_id: NamespaceId) -> miette::Result<()> {
let ticket = mainline::Bytes::from(
self.create_document_ticket(namespace_id.clone(), ShareMode::Read)
self.create_document_ticket(namespace_id, ShareMode::Read)
.await?
.to_bytes(),
);
Expand All @@ -29,7 +29,7 @@ impl OkuFs {
.await? as i64;
let replica_private_key = mainline::SigningKey::from_bytes(
&self
.create_document_ticket(namespace_id.clone(), ShareMode::Write)
.create_document_ticket(namespace_id, ShareMode::Write)
.await?
.capability
.secret_key()
Expand Down Expand Up @@ -58,7 +58,7 @@ impl OkuFs {
.await
.ok_or(miette::miette!("No home replica set … "))?;
let ticket = mainline::Bytes::from(
self.create_document_ticket(home_replica.clone(), ShareMode::Read)
self.create_document_ticket(home_replica, ShareMode::Read)
.await?
.to_bytes(),
);
Expand Down
5 changes: 2 additions & 3 deletions src/fs/core.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,15 +34,14 @@ impl OkuFs {
/// The private key of the node's authorship credentials.
pub async fn get_author(&self) -> anyhow::Result<Author> {
let default_author_id = self.node.authors().default().await?;
Ok(self
.node
self.node
.authors()
.export(default_author_id)
.await?
.ok_or(anyhow!(
"Missing private key for default author ({}).",
default_author_id.fmt_short()
))?)
))
}

/// Starts an instance of an Oku file system.
Expand Down
13 changes: 5 additions & 8 deletions src/fs/directory.rs
Original file line number Diff line number Diff line change
Expand Up @@ -152,11 +152,9 @@ impl OkuFs {
entries_deleted += document
.del(
file.author(),
format!(
"{}",
std::str::from_utf8(&path_to_entry_prefix(entry_key_to_path(file.key())?))
.into_diagnostic()?
),
(std::str::from_utf8(&path_to_entry_prefix(entry_key_to_path(file.key())?))
.into_diagnostic()?)
.to_string(),
)
.await
.map_err(|e| {
Expand Down Expand Up @@ -261,9 +259,8 @@ impl OkuFs {
let replica = self
.fetch_replica_by_ticket(ticket, Some(path.clone()))
.await?;
Ok(self
.read_directory_from_replica_handle(replica, path)
self.read_directory_from_replica_handle(replica, path)
.await
.map_err(|e| anyhow!("{}", e))?)
.map_err(|e| anyhow!("{}", e))
}
}
7 changes: 3 additions & 4 deletions src/fs/file.rs
Original file line number Diff line number Diff line change
Expand Up @@ -330,7 +330,7 @@ impl OkuFs {
namespace_id: NamespaceId,
path: PathBuf,
) -> anyhow::Result<Bytes> {
match self.resolve_namespace_id(namespace_id.clone()).await {
match self.resolve_namespace_id(namespace_id).await {
Ok(ticket) => match self.fetch_file_with_ticket(&ticket, path.clone()).await {
Ok(bytes) => Ok(bytes),
Err(e) => {
Expand Down Expand Up @@ -391,9 +391,8 @@ impl OkuFs {
break;
}
}
Ok(self
.read_file(namespace_id, path)
self.read_file(namespace_id, path)
.await
.map_err(|e| anyhow!("{}", e))?)
.map_err(|e| anyhow!("{}", e))
}
}
Loading

0 comments on commit 3fe2c76

Please sign in to comment.