Skip to content

Commit

Permalink
Safely handle missing document when retrieving document view from sto…
Browse files Browse the repository at this point in the history
…re (#637)

* Return None when document was deleted

* Add entry to CHANGELOG.md
  • Loading branch information
adzialocha authored Jun 26, 2024
1 parent d0df119 commit 04b12ae
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 10 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Handle connection ids greater than 9 in `Peer` impl of `Human` trait [#634](https://github.com/p2panda/aquadoggo/pull/634)
- Check if blob file exists before deleting it from fs [#636](https://github.com/p2panda/aquadoggo/pull/636)
- Inconsistent blob storage warning was wrongly shown [#638](https://github.com/p2panda/aquadoggo/pull/638)
- Safely handle missing document when retrieving document view from store [#637](https://github.com/p2panda/aquadoggo/pull/637)

## [0.7.4]

Expand Down
24 changes: 14 additions & 10 deletions aquadoggo/src/db/stores/document.rs
Original file line number Diff line number Diff line change
Expand Up @@ -170,8 +170,12 @@ impl DocumentStore for SqlStore {
.await
.map_err(|e| DocumentStorageError::FatalStorageError(e.to_string()))?;

// Unwrap as we can assume a document for the found document id exists.
let document_row = document_row.unwrap();
// If no row matched we return None here, otherwise unwrap safely
let document_row = match document_row {
Some(document_row) => document_row,
// Document might have already been deleted
None => return Ok(None),
};

// We now want to retrieve the view (current key-value map) for this document, as we
// already filtered out deleted documents in the query above we can expect all documents
Expand Down Expand Up @@ -220,7 +224,7 @@ impl DocumentStore for SqlStore {
ON
operations_v1.operation_id = documents.document_id
WHERE
documents.schema_id = $1 AND documents.is_deleted = false
documents.schema_id = $1 AND documents.is_deleted = false
",
)
.bind(schema_id.to_string())
Expand Down Expand Up @@ -420,9 +424,9 @@ impl SqlStore {
document_view_fields.name = operation_fields_v1.name
WHERE
operation_fields_v1.field_type IN (
'pinned_relation',
'pinned_relation_list',
'relation',
'pinned_relation',
'pinned_relation_list',
'relation',
'relation_list'
)
AND
Expand Down Expand Up @@ -539,11 +543,11 @@ impl SqlStore {
) -> Result<bool, DocumentStorageError> {
let document_view_id: Option<String> = query_scalar(
"
SELECT
documents.document_view_id
FROM
SELECT
documents.document_view_id
FROM
documents
WHERE
WHERE
documents.document_view_id = $1
",
)
Expand Down

0 comments on commit 04b12ae

Please sign in to comment.