Skip to content

Commit

Permalink
client-api: make some BAD_REQUEST into NOT_FOUND (#1768)
Browse files Browse the repository at this point in the history
  • Loading branch information
Centril authored Sep 30, 2024
1 parent a15f60b commit dd52cda
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 6 deletions.
4 changes: 2 additions & 2 deletions crates/client-api/src/routes/identity.rs
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,7 @@ pub async fn confirm_recovery_code<S: ControlStateDelegate + NodeDelegate>(
let recovery_code = recovery_codes
.into_iter()
.find(|rc| rc.code == code.as_str())
.ok_or((StatusCode::BAD_REQUEST, "Recovery code not found."))?;
.ok_or((StatusCode::NOT_FOUND, "Recovery code not found."))?;

let duration = Utc::now() - recovery_code.generation_time;
if duration.num_seconds() > 60 * 10 {
Expand All @@ -310,7 +310,7 @@ pub async fn confirm_recovery_code<S: ControlStateDelegate + NodeDelegate>(
.any(|a| a.identity == identity)
{
// This can happen if someone changes their associated email during a recovery request.
return Err((StatusCode::BAD_REQUEST, "No identity associated with that email.").into());
return Err((StatusCode::NOT_FOUND, "No identity associated with that email.").into());
}

// Recovery code is verified, return the identity and token to the user
Expand Down
4 changes: 2 additions & 2 deletions crates/client-api/src/routes/subscribe.rs
Original file line number Diff line number Diff line change
Expand Up @@ -87,10 +87,10 @@ where
let database = ctx
.get_database_by_address(&db_address)
.unwrap()
.ok_or(StatusCode::BAD_REQUEST)?;
.ok_or(StatusCode::NOT_FOUND)?;
let database_instance = ctx
.get_leader_database_instance_by_database(database.id)
.ok_or(StatusCode::BAD_REQUEST)?;
.ok_or(StatusCode::NOT_FOUND)?;
let instance_id = database_instance.id;

let identity_token = auth.creds.token().to_owned();
Expand Down
4 changes: 2 additions & 2 deletions crates/client-api/src/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -109,14 +109,14 @@ impl NameOrAddress {
})
}

/// A variant of [`Self::try_resolve()`] which maps to a 400 (Bad Request)
/// A variant of [`Self::try_resolve()`] which maps to a 404 (Not Found)
/// response if `self` is a [`NameOrAddress::Name`] for which no
/// corresponding [`Address`] is found in the SpacetimeDB DNS.
pub async fn resolve(
&self,
ctx: &(impl ControlStateReadAccess + ?Sized),
) -> axum::response::Result<ResolvedAddress> {
self.try_resolve(ctx).await?.map_err(|_| StatusCode::BAD_REQUEST.into())
self.try_resolve(ctx).await?.map_err(|_| StatusCode::NOT_FOUND.into())
}
}

Expand Down

2 comments on commit dd52cda

@github-actions
Copy link

@github-actions github-actions bot commented on dd52cda Sep 30, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Callgrind benchmark results

Callgrind Benchmark Report

These benchmarks were run using callgrind,
an instruction-level profiler. They allow comparisons between sqlite (sqlite), SpacetimeDB running through a module (stdb_module), and the underlying SpacetimeDB data storage engine (stdb_raw). Callgrind emulates a CPU to collect the below estimates.

Measurement changes larger than five percent are in bold.

In-memory benchmarks

callgrind: empty transaction

db total reads + writes old total reads + writes Δrw estimated cycles old estimated cycles Δcycles
stdb_raw 5397 5397 0.00% 5481 5481 0.00%
sqlite 5555 5555 0.00% 5909 5909 0.00%

callgrind: filter

db schema indices count preload _column data_type total reads + writes old total reads + writes Δrw estimated cycles old estimated cycles Δcycles
stdb_raw u32_u64_str no_index 64 128 2 string 117796 117796 0.00% 118270 118270 0.00%
stdb_raw u32_u64_str no_index 64 128 1 u64 75385 75385 0.00% 75687 75707 -0.03%
stdb_raw u32_u64_str btree_each_column 64 128 2 string 24057 24058 -0.00% 24467 24468 -0.00%
stdb_raw u32_u64_str btree_each_column 64 128 1 u64 23025 23025 0.00% 23383 23383 0.00%
sqlite u32_u64_str no_index 64 128 2 string 144619 144619 0.00% 146203 146199 0.00%
sqlite u32_u64_str no_index 64 128 1 u64 124007 124007 0.00% 125267 125267 0.00%
sqlite u32_u64_str btree_each_column 64 128 2 string 134418 134418 0.00% 136074 136066 0.01%
sqlite u32_u64_str btree_each_column 64 128 1 u64 131324 131324 0.00% 132692 132684 0.01%

callgrind: insert bulk

db schema indices count preload total reads + writes old total reads + writes Δrw estimated cycles old estimated cycles Δcycles
stdb_raw u32_u64_str unique_0 64 128 896556 896950 -0.04% 957432 957914 -0.05%
stdb_raw u32_u64_str btree_each_column 64 128 1049395 1051170 -0.17% 1091059 1093464 -0.22%
sqlite u32_u64_str unique_0 64 128 398156 398156 0.00% 417468 417472 -0.00%
sqlite u32_u64_str btree_each_column 64 128 983473 983473 0.00% 1028279 1028283 -0.00%

callgrind: iterate

db schema indices count total reads + writes old total reads + writes Δrw estimated cycles old estimated cycles Δcycles
stdb_raw u32_u64_str unique_0 1024 152683 152683 0.00% 152749 152749 0.00%
stdb_raw u32_u64_str unique_0 64 15708 15708 0.00% 15746 15746 0.00%
sqlite u32_u64_str unique_0 1024 1067203 1067203 0.00% 1070493 1070493 0.00%
sqlite u32_u64_str unique_0 64 76149 76149 0.00% 77185 77185 0.00%

callgrind: serialize_product_value

count format total reads + writes old total reads + writes Δrw estimated cycles old estimated cycles Δcycles
64 json 47374 47374 0.00% 49958 49958 0.00%
64 bsatn 25716 25716 0.00% 28028 28028 0.00%
16 json 12126 12126 0.00% 13962 13962 0.00%
16 bsatn 8117 8117 0.00% 9511 9511 0.00%

callgrind: update bulk

db schema indices count preload total reads + writes old total reads + writes Δrw estimated cycles old estimated cycles Δcycles
stdb_raw u32_u64_str unique_0 1024 1024 20627064 20621843 0.03% 21357548 21349553 0.04%
stdb_raw u32_u64_str unique_0 64 128 1301232 1301690 -0.04% 1383064 1352242 2.28%
sqlite u32_u64_str unique_0 1024 1024 1802091 1802091 0.00% 1811199 1811195 0.00%
sqlite u32_u64_str unique_0 64 128 128437 128437 0.00% 131283 131283 0.00%
On-disk benchmarks

callgrind: empty transaction

db total reads + writes old total reads + writes Δrw estimated cycles old estimated cycles Δcycles
stdb_raw 5407 5407 0.00% 5483 5483 0.00%
sqlite 5597 5597 0.00% 6019 6019 0.00%

callgrind: filter

db schema indices count preload _column data_type total reads + writes old total reads + writes Δrw estimated cycles old estimated cycles Δcycles
stdb_raw u32_u64_str no_index 64 128 2 string 117806 117806 0.00% 118256 118252 0.00%
stdb_raw u32_u64_str no_index 64 128 1 u64 75395 75395 0.00% 75681 75681 0.00%
stdb_raw u32_u64_str btree_each_column 64 128 2 string 24067 24067 0.00% 24457 24473 -0.07%
stdb_raw u32_u64_str btree_each_column 64 128 1 u64 23035 23035 0.00% 23353 23353 0.00%
sqlite u32_u64_str no_index 64 128 2 string 146540 146540 0.00% 148392 148400 -0.01%
sqlite u32_u64_str no_index 64 128 1 u64 125928 125928 0.00% 127508 127508 0.00%
sqlite u32_u64_str btree_each_column 64 128 2 string 136540 136540 0.00% 138790 138790 0.00%
sqlite u32_u64_str btree_each_column 64 128 1 u64 133420 133420 0.00% 135354 135354 0.00%

callgrind: insert bulk

db schema indices count preload total reads + writes old total reads + writes Δrw estimated cycles old estimated cycles Δcycles
stdb_raw u32_u64_str unique_0 64 128 845871 845604 0.03% 906581 906474 0.01%
stdb_raw u32_u64_str btree_each_column 64 128 997594 996666 0.09% 1039520 1068768 -2.74%
sqlite u32_u64_str unique_0 64 128 415693 415693 0.00% 434487 434487 0.00%
sqlite u32_u64_str btree_each_column 64 128 1021734 1021734 0.00% 1065814 1065834 -0.00%

callgrind: iterate

db schema indices count total reads + writes old total reads + writes Δrw estimated cycles old estimated cycles Δcycles
stdb_raw u32_u64_str unique_0 1024 152693 152693 0.00% 152731 152731 0.00%
stdb_raw u32_u64_str unique_0 64 15718 15718 0.00% 15756 15760 -0.03%
sqlite u32_u64_str unique_0 1024 1070271 1070271 0.00% 1074019 1074019 0.00%
sqlite u32_u64_str unique_0 64 77921 77921 0.00% 79237 79237 0.00%

callgrind: serialize_product_value

count format total reads + writes old total reads + writes Δrw estimated cycles old estimated cycles Δcycles
64 json 47374 47374 0.00% 49958 49958 0.00%
64 bsatn 25716 25716 0.00% 28028 28028 0.00%
16 json 12126 12126 0.00% 13962 13962 0.00%
16 bsatn 8117 8117 0.00% 9511 9511 0.00%

callgrind: update bulk

db schema indices count preload total reads + writes old total reads + writes Δrw estimated cycles old estimated cycles Δcycles
stdb_raw u32_u64_str unique_0 1024 1024 19326511 19323173 0.02% 20108185 20102991 0.03%
stdb_raw u32_u64_str unique_0 64 128 1254420 1254413 0.00% 1335244 1334971 0.02%
sqlite u32_u64_str unique_0 1024 1024 1809652 1809652 0.00% 1818204 1818204 0.00%
sqlite u32_u64_str unique_0 64 128 132569 132563 0.00% 135495 135489 0.00%

@github-actions
Copy link

@github-actions github-actions bot commented on dd52cda Sep 30, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Criterion benchmark results

Error when comparing benchmarks:

Caused by:

Please sign in to comment.