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’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(torii-grpc): member clause should never error out if no entities #2418

Merged
merged 3 commits into from
Sep 12, 2024
Merged
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
27 changes: 20 additions & 7 deletions crates/torii/grpc/src/server/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,8 @@
"#
);
// total count of rows without limit and offset
let total_count: u32 = sqlx::query_scalar(&count_query).fetch_one(&self.pool).await?;
let total_count: u32 =
sqlx::query_scalar(&count_query).fetch_optional(&self.pool).await?.unwrap_or(0);

Check warning on line 261 in crates/torii/grpc/src/server/mod.rs

View check run for this annotation

Codecov / codecov/patch

crates/torii/grpc/src/server/mod.rs#L260-L261

Added lines #L260 - L261 were not covered by tests

if total_count == 0 {
return Ok((Vec::new(), 0));
Expand Down Expand Up @@ -375,8 +376,11 @@
}
);

let total_count =
sqlx::query_scalar(&count_query).bind(&keys_pattern).fetch_one(&self.pool).await?;
let total_count = sqlx::query_scalar(&count_query)
.bind(&keys_pattern)
.fetch_optional(&self.pool)
.await?
.unwrap_or(0);

if total_count == 0 {
return Ok((Vec::new(), 0));
Expand Down Expand Up @@ -521,7 +525,15 @@
"#,
compute_selector_from_names(namespace, model)
);
let (models_str,): (String,) = sqlx::query_as(&models_query).fetch_one(&self.pool).await?;

let models_result: Option<(String,)> =
sqlx::query_as(&models_query).fetch_optional(&self.pool).await?;

Check warning on line 530 in crates/torii/grpc/src/server/mod.rs

View check run for this annotation

Codecov / codecov/patch

crates/torii/grpc/src/server/mod.rs#L529-L530

Added lines #L529 - L530 were not covered by tests
// we return an empty array of entities if the table is empty
if models_result.is_none() {
return Ok((Vec::new(), 0));
}

let (models_str,) = models_result.unwrap();

Check warning on line 536 in crates/torii/grpc/src/server/mod.rs

View check run for this annotation

Codecov / codecov/patch

crates/torii/grpc/src/server/mod.rs#L532-L536

Added lines #L532 - L536 were not covered by tests

let model_ids = models_str
.split(',')
Expand All @@ -545,8 +557,9 @@

let total_count = sqlx::query_scalar(&count_query)
.bind(comparison_value.clone())
.fetch_one(&self.pool)
.await?;
.fetch_optional(&self.pool)
.await?
.unwrap_or(0);

Check warning on line 562 in crates/torii/grpc/src/server/mod.rs

View check run for this annotation

Codecov / codecov/patch

crates/torii/grpc/src/server/mod.rs#L560-L562

Added lines #L560 - L562 were not covered by tests

let db_entities = sqlx::query(&entity_query)
.bind(comparison_value.clone())
Expand Down Expand Up @@ -671,7 +684,7 @@
count_query = count_query.bind(value);
}

let total_count = count_query.fetch_one(&self.pool).await?;
let total_count = count_query.fetch_optional(&self.pool).await?.unwrap_or(0);

Check warning on line 687 in crates/torii/grpc/src/server/mod.rs

View check run for this annotation

Codecov / codecov/patch

crates/torii/grpc/src/server/mod.rs#L687

Added line #L687 was not covered by tests

if total_count == 0 {
return Ok((Vec::new(), 0));
Expand Down
Loading