Skip to content

Commit

Permalink
use optional
Browse files Browse the repository at this point in the history
  • Loading branch information
smklein committed Oct 11, 2023
1 parent e925b89 commit 48363a1
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 8 deletions.
2 changes: 1 addition & 1 deletion nexus/db-queries/src/db/datastore/region_snapshot.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ use crate::db::error::public_error_from_diesel;
use crate::db::error::ErrorHandler;
use crate::db::model::RegionSnapshot;
use async_bb8_diesel::AsyncRunQueryDsl;
use async_bb8_diesel::OptionalExtension;
use diesel::prelude::*;
use diesel::OptionalExtension;
use omicron_common::api::external::CreateResult;
use omicron_common::api::external::DeleteResult;
use omicron_common::api::external::LookupResult;
Expand Down
10 changes: 3 additions & 7 deletions nexus/db-queries/src/db/datastore/snapshot.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ use async_bb8_diesel::AsyncConnection;
use async_bb8_diesel::AsyncRunQueryDsl;
use chrono::Utc;
use diesel::prelude::*;
use diesel::result::Error as DieselError;
use diesel::OptionalExtension;
use nexus_types::identity::Resource;
use omicron_common::api::external::http_pagination::PaginatedBy;
use omicron_common::api::external::CreateResult;
Expand Down Expand Up @@ -100,19 +100,15 @@ impl DataStore {
// does not match, but a project and name that does, return
// ObjectAlreadyExists here.

let existing_snapshot_id: Option<Uuid> = match dsl::snapshot
let existing_snapshot_id: Option<Uuid> = dsl::snapshot
.filter(dsl::time_deleted.is_null())
.filter(dsl::name.eq(snapshot.name().to_string()))
.filter(dsl::project_id.eq(snapshot.project_id))
.select(dsl::id)
.limit(1)
.first_async(&conn)
.await
{
Ok(v) => Ok(Some(v)),
Err(DieselError::NotFound) => Ok(None),
Err(e) => Err(e),
}?;
.optional()?;

if let Some(existing_snapshot_id) = existing_snapshot_id {
if existing_snapshot_id != snapshot.id() {
Expand Down

0 comments on commit 48363a1

Please sign in to comment.