Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Safely handle missing document when retrieving document view from store #637

Merged
merged 2 commits into from
Jun 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading