Skip to content

Commit

Permalink
Do not use get_range for Table<BatchInfo>
Browse files Browse the repository at this point in the history
The function has been removed from review-database-0.25.
  • Loading branch information
msk committed Feb 6, 2024
1 parent 39abed2 commit b7ce907
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 21 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ oinq = { git = "https://github.com/petabi/oinq.git", tag = "0.9.1" }
reqwest = { version = "0.11", default-features = false, features = [
"rustls-tls-native-roots",
] }
review-database = { git = "https://github.com/petabi/review-database.git", rev = "dec7c5e6" }
review-database = { git = "https://github.com/petabi/review-database.git", rev = "1e9dfeeb" }
roxy = { git = "https://github.com/aicers/roxy.git", tag = "0.2.1" }
rustls = "0.21"
rustls-native-certs = "0.6"
Expand Down
6 changes: 4 additions & 2 deletions src/graphql.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ pub use self::cert::ParsedCertificate;
pub use self::customer::get_customer_networks;
pub use self::node::{get_customer_id_of_review_host, get_node_settings};
pub use self::trusted_user_agent::get_trusted_user_agent_list;
use async_graphql::connection::ConnectionNameType;
use async_graphql::{
connection::{Connection, Edge, EmptyFields},
Context, Guard, MergedObject, MergedSubscription, ObjectType, OutputType, Result,
Expand Down Expand Up @@ -438,18 +439,19 @@ fn always_true(_ordering: cmp::Ordering) -> bool {
true
}

fn load_edges<R, N, A>(
fn load_edges<R, N, A, NodesField>(
table: &database::Table<'_, R>,
after: Option<String>,
before: Option<String>,
mut first: Option<usize>,
last: Option<usize>,
additional_fields: A,
) -> Result<Connection<String, N, A, EmptyFields>>
) -> Result<Connection<String, N, A, EmptyFields, NodesField>>
where
R: DeserializeOwned + database::UniqueKey,
N: From<R> + OutputType,
A: ObjectType,
NodesField: ConnectionNameType,
{
if first.is_some() && last.is_some() {
return Err("cannot provide both `first` and `last`".into());
Expand Down
30 changes: 12 additions & 18 deletions src/graphql/statistics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ impl StatisticsQuery {
first,
last,
|after, before, first, last| async move {
load_rounds_by_model(ctx, model, &after, &before, first, last).await
load_rounds_by_model(ctx, model, after, before, first, last).await
},
)
.await
Expand Down Expand Up @@ -184,27 +184,21 @@ async fn load_rounds_by_cluster(
async fn load_rounds_by_model(
ctx: &Context<'_>,
model: i32,
after: &Option<String>,
before: &Option<String>,
after: Option<String>,
before: Option<String>,
first: Option<usize>,
last: Option<usize>,
) -> Result<Connection<String, Round, TotalCountByModel, EmptyFields, RoundByModel>> {
let after: Option<i64> = slicing::decode_cursor(after)?.map(|(_, t)| t);
let before: Option<i64> = slicing::decode_cursor(before)?.map(|(_, t)| t);
let is_first = first.is_some();
let limit = slicing::limit(first, last)?;
let store = super::get_store(ctx).await?;
let map = store.batch_info_map();
let batch_infos: Vec<BatchInfo> = map.get_range(model, before, after, is_first, limit + 1)?;

let (rows, has_previous, has_next) = slicing::page_info(is_first, limit, batch_infos);
let mut connection =
Connection::with_additional_fields(has_previous, has_next, TotalCountByModel { model });
connection.edges.extend(rows.into_iter().map(|row| {
let cursor = slicing::encode_cursor(row.model, row.inner.id);
Edge::new(cursor, row.into())
}));
Ok(connection)
let table = store.batch_info_map();
super::load_edges(
&table,
after,
before,
first,
last,
TotalCountByModel { model },
)
}

fn i64_to_naive_date_time(t: i64) -> NaiveDateTime {
Expand Down

0 comments on commit b7ce907

Please sign in to comment.