Skip to content

Commit 3fe2c76

Browse files
committed
feat: OkuNet tags
1 parent f48425d commit 3fe2c76

File tree

9 files changed

+104
-65
lines changed

9 files changed

+104
-65
lines changed

.github/old-workflows/main.yml renamed to .github/workflows/main.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ jobs:
1919
- name: Checkout codebase
2020
uses: actions/checkout@v4
2121
- name: Generate documentation
22-
run: time cargo doc --no-deps -Zrustdoc-map --release --quiet
22+
run: time cargo doc --no-deps
2323
- name: Fix permissions
2424
run: |
2525
chmod -c -R +rX "target/doc/" | while read line; do
@@ -60,7 +60,7 @@ jobs:
6060
- name: Apply compiler suggestions
6161
run: |
6262
cargo fix --edition --edition-idioms --allow-dirty
63-
cargo clippy --fix -Z unstable-options --allow-dirty
63+
cargo clippy --fix --allow-dirty
6464
- name: Commit changes to code, if any
6565
run: |
6666
git config user.name github-actions

src/config.rs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -51,11 +51,7 @@ impl OkuFsConfig {
5151

5252
/// The home replica of the node.
5353
pub fn home_replica(&self) -> miette::Result<Option<NamespaceId>> {
54-
Ok(self
55-
.home_replica
56-
.try_lock()
57-
.map_err(|e| miette!("{}", e))?
58-
.clone())
54+
Ok(*self.home_replica.try_lock().map_err(|e| miette!("{}", e))?)
5955
}
6056

6157
/// Sets the home replica of the node.

src/database.rs

Lines changed: 21 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ pub struct OkuIdentity {
119119
pub blocked: HashSet<AuthorId>,
120120
}
121121

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

135+
impl PartialEq for OkuPost {
136+
fn eq(&self, other: &Self) -> bool {
137+
self.primary_key() == other.primary_key()
138+
}
139+
}
140+
impl Eq for OkuPost {}
141+
impl Hash for OkuPost {
142+
fn hash<H: Hasher>(&self, state: &mut H) {
143+
self.primary_key().hash(state);
144+
}
145+
}
146+
135147
impl From<OkuPost> for TantivyDocument {
136148
fn from(value: OkuPost) -> Self {
137149
let post_key: [Vec<u8>; 2] = value.primary_key().into();
@@ -276,7 +288,7 @@ impl OkuDatabase {
276288
) -> miette::Result<Vec<OkuPost>> {
277289
let searcher = POST_INDEX_READER.searcher();
278290
let query_parser = QueryParser::for_index(
279-
&*POST_INDEX,
291+
&POST_INDEX,
280292
vec![
281293
POST_SCHEMA.1["author_id"],
282294
POST_SCHEMA.1["path"],
@@ -422,13 +434,13 @@ impl OkuDatabase {
422434
/// A list of all known OkuNet posts.
423435
pub fn get_posts(&self) -> miette::Result<Vec<OkuPost>> {
424436
let r = self.database.r_transaction().into_diagnostic()?;
425-
Ok(r.scan()
437+
r.scan()
426438
.primary()
427439
.into_diagnostic()?
428440
.all()
429441
.into_diagnostic()?
430442
.collect::<Result<Vec<_>, _>>()
431-
.into_diagnostic()?)
443+
.into_diagnostic()
432444
}
433445

434446
/// Retrieves all known OkuNet posts by a given author.
@@ -495,7 +507,7 @@ impl OkuDatabase {
495507
author_id.as_bytes().to_vec(),
496508
path_to_entry_key(path).to_vec(),
497509
);
498-
Ok(r.get().primary(entry_key).into_diagnostic()?)
510+
r.get().primary(entry_key).into_diagnostic()
499511
}
500512

501513
/// Insert or update an OkuNet user.
@@ -629,13 +641,13 @@ impl OkuDatabase {
629641
/// The OkuNet content of all users known to this node.
630642
pub fn get_users(&self) -> miette::Result<Vec<OkuUser>> {
631643
let r = self.database.r_transaction().into_diagnostic()?;
632-
Ok(r.scan()
644+
r.scan()
633645
.primary()
634646
.into_diagnostic()?
635647
.all()
636648
.into_diagnostic()?
637649
.collect::<Result<Vec<_>, _>>()
638-
.into_diagnostic()?)
650+
.into_diagnostic()
639651
}
640652

641653
/// Gets an OkuNet user's content by their content authorship ID.
@@ -649,8 +661,8 @@ impl OkuDatabase {
649661
/// An OkuNet user's content.
650662
pub fn get_user(&self, author_id: AuthorId) -> miette::Result<Option<OkuUser>> {
651663
let r = self.database.r_transaction().into_diagnostic()?;
652-
Ok(r.get()
664+
r.get()
653665
.primary(author_id.as_bytes().to_vec())
654-
.into_diagnostic()?)
666+
.into_diagnostic()
655667
}
656668
}

src/discovery.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ impl OkuFs {
2020
/// * `namespace_id` - The ID of the replica to announce.
2121
pub async fn announce_replica(&self, namespace_id: NamespaceId) -> miette::Result<()> {
2222
let ticket = mainline::Bytes::from(
23-
self.create_document_ticket(namespace_id.clone(), ShareMode::Read)
23+
self.create_document_ticket(namespace_id, ShareMode::Read)
2424
.await?
2525
.to_bytes(),
2626
);
@@ -29,7 +29,7 @@ impl OkuFs {
2929
.await? as i64;
3030
let replica_private_key = mainline::SigningKey::from_bytes(
3131
&self
32-
.create_document_ticket(namespace_id.clone(), ShareMode::Write)
32+
.create_document_ticket(namespace_id, ShareMode::Write)
3333
.await?
3434
.capability
3535
.secret_key()
@@ -58,7 +58,7 @@ impl OkuFs {
5858
.await
5959
.ok_or(miette::miette!("No home replica set … "))?;
6060
let ticket = mainline::Bytes::from(
61-
self.create_document_ticket(home_replica.clone(), ShareMode::Read)
61+
self.create_document_ticket(home_replica, ShareMode::Read)
6262
.await?
6363
.to_bytes(),
6464
);

src/fs/core.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,15 +34,14 @@ impl OkuFs {
3434
/// The private key of the node's authorship credentials.
3535
pub async fn get_author(&self) -> anyhow::Result<Author> {
3636
let default_author_id = self.node.authors().default().await?;
37-
Ok(self
38-
.node
37+
self.node
3938
.authors()
4039
.export(default_author_id)
4140
.await?
4241
.ok_or(anyhow!(
4342
"Missing private key for default author ({}).",
4443
default_author_id.fmt_short()
45-
))?)
44+
))
4645
}
4746

4847
/// Starts an instance of an Oku file system.

src/fs/directory.rs

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -152,11 +152,9 @@ impl OkuFs {
152152
entries_deleted += document
153153
.del(
154154
file.author(),
155-
format!(
156-
"{}",
157-
std::str::from_utf8(&path_to_entry_prefix(entry_key_to_path(file.key())?))
158-
.into_diagnostic()?
159-
),
155+
(std::str::from_utf8(&path_to_entry_prefix(entry_key_to_path(file.key())?))
156+
.into_diagnostic()?)
157+
.to_string(),
160158
)
161159
.await
162160
.map_err(|e| {
@@ -261,9 +259,8 @@ impl OkuFs {
261259
let replica = self
262260
.fetch_replica_by_ticket(ticket, Some(path.clone()))
263261
.await?;
264-
Ok(self
265-
.read_directory_from_replica_handle(replica, path)
262+
self.read_directory_from_replica_handle(replica, path)
266263
.await
267-
.map_err(|e| anyhow!("{}", e))?)
264+
.map_err(|e| anyhow!("{}", e))
268265
}
269266
}

src/fs/file.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -330,7 +330,7 @@ impl OkuFs {
330330
namespace_id: NamespaceId,
331331
path: PathBuf,
332332
) -> anyhow::Result<Bytes> {
333-
match self.resolve_namespace_id(namespace_id.clone()).await {
333+
match self.resolve_namespace_id(namespace_id).await {
334334
Ok(ticket) => match self.fetch_file_with_ticket(&ticket, path.clone()).await {
335335
Ok(bytes) => Ok(bytes),
336336
Err(e) => {
@@ -391,9 +391,8 @@ impl OkuFs {
391391
break;
392392
}
393393
}
394-
Ok(self
395-
.read_file(namespace_id, path)
394+
self.read_file(namespace_id, path)
396395
.await
397-
.map_err(|e| anyhow!("{}", e))?)
396+
.map_err(|e| anyhow!("{}", e))
398397
}
399398
}

0 commit comments

Comments
 (0)