Skip to content

Commit

Permalink
Small fixes and comments to relations2 (#1675)
Browse files Browse the repository at this point in the history
  • Loading branch information
jotare authored Dec 18, 2023
1 parent 050596e commit 3958c09
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 6 deletions.
16 changes: 13 additions & 3 deletions nucliadb_relations2/src/schema.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,56 +89,66 @@ impl Schema {
normalized_target_value,
}
}

pub fn resource_id(&self, doc: &Document) -> String {
doc.get_first(self.resource_id)
.and_then(|i| i.as_text().map(String::from))
.expect("Dos must have a resource id")
.expect("Documents must have a resource id")
}

pub fn source_value(&self, doc: &Document) -> String {
doc.get_first(self.source_value)
.and_then(|i| i.as_text())
.map(String::from)
.expect("Documents must have a source value")
}

pub fn source_type(&self, doc: &Document) -> u64 {
doc.get_first(self.source_type)
.and_then(|i| i.as_u64())
.expect("Documents must have a source type")
}

pub fn source_subtype(&self, doc: &Document) -> String {
doc.get_first(self.source_subtype)
.and_then(|i| i.as_text())
.map(String::from)
.expect("Documents must have a source subtype")
}

pub fn target_value(&self, doc: &Document) -> String {
doc.get_first(self.target_value)
.and_then(|i| i.as_text())
.map(String::from)
.expect("Documents must have a target value")
}

pub fn target_type(&self, doc: &Document) -> u64 {
doc.get_first(self.target_type)
.and_then(|i| i.as_u64())
.expect("Documents must have a target type")
}

pub fn target_subtype(&self, doc: &Document) -> String {
doc.get_first(self.target_subtype)
.and_then(|i| i.as_text())
.map(String::from)
.expect("Documents must have a target subtype")
}

pub fn relationship(&self, doc: &Document) -> u64 {
doc.get_first(self.relationship)
.and_then(|i| i.as_u64())
.expect("Documents must have a relation type")
.expect("Documents must have a relationship type")
}

pub fn relationship_label(&self, doc: &Document) -> String {
doc.get_first(self.label)
.and_then(|i| i.as_text())
.map(String::from)
.expect("Documents must have a relation label")
.expect("Documents must have a relationship label")
}

pub fn metadata<'a>(&self, doc: &'a Document) -> Option<&'a [u8]> {
doc.get_first(self.metadata).and_then(|i| i.as_bytes())
}
Expand Down
7 changes: 4 additions & 3 deletions nucliadb_relations2/src/writer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ impl FieldWriter for RelationsWriterService {}
impl RelationWriter for RelationsWriterService {}

impl WriterChild for RelationsWriterService {
#[measure(actor = "texts", metric = "count")]
#[measure(actor = "relations" metric = "count")]
#[tracing::instrument(skip_all)]
fn count(&self) -> NodeResult<usize> {
let reader = self.index.reader()?;
Expand All @@ -71,13 +71,14 @@ impl WriterChild for RelationsWriterService {
Ok(count)
}

#[measure(actor = "texts", metric = "set_resource")]
#[measure(actor = "relations", metric = "set_resource")]
#[tracing::instrument(skip_all)]
fn set_resource(&mut self, resource: &Resource) -> NodeResult<()> {
let resource_id = resource.resource.as_ref().expect("Missing resource ID");
let uuid_field = self.schema.resource_id;
let uuid_term = Term::from_field_text(uuid_field, &resource_id.uuid);
self.writer.delete_term(uuid_term);
// REVIEW: are we sure we want to index in every other ResourceStatus?
if resource.status != ResourceStatus::Delete as i32 {
self.index_document(resource)?;
}
Expand All @@ -86,7 +87,7 @@ impl WriterChild for RelationsWriterService {
Ok(())
}

#[measure(actor = "texts", metric = "delete_resource")]
#[measure(actor = "relations", metric = "delete_resource")]
#[tracing::instrument(skip_all)]
fn delete_resource(&mut self, resource_id: &ResourceId) -> NodeResult<()> {
let uuid_field = self.schema.resource_id;
Expand Down

0 comments on commit 3958c09

Please sign in to comment.