Skip to content

Commit

Permalink
m
Browse files Browse the repository at this point in the history
  • Loading branch information
bmwill committed Sep 5, 2024
1 parent 6e02d1c commit f8eb2ca
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 28 deletions.
21 changes: 10 additions & 11 deletions crates/sui-graphql-rpc/src/data.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,27 +57,26 @@ pub(crate) trait QueryExecutor {
/// issue queries over.
async fn execute<'c, T, U, E>(&self, txn: T) -> Result<U, Error>
where
// T: FnOnce(&'a mut Self::DbConnection<'c>) -> Fut,
// 'a: 'c,
// Fut: std::future::Future<Output = Result<U, E>> + Send + 'a,
T: for<'r> FnOnce(&'r mut Self::DbConnection<'_>) -> ScopedBoxFuture<'static, 'r, Result<U, E>> + Send + 'c,
T: for<'r> FnOnce(
&'r mut Self::DbConnection<'_>,
) -> ScopedBoxFuture<'static, 'r, Result<U, E>>
+ Send
+ 'c,
E: From<diesel::result::Error> + std::error::Error,
T: Send + 'static,
U: Send + 'static,
E: Send + 'static;
// T: for<'r> FnOnce(&'r mut Self::DbConnection<'_>) -> ScopedBoxFuture<'b, 'r, Result<U, E>>
// + Send,
// U: 'b,
// E: From<diesel::result::Error> + std::error::Error + 'b;

/// Execute `txn` with repeatable reads and no phantom reads -- multiple calls to the same query
/// should produce the same results. `txn` is supplied a database connection to issue queries
/// over.
async fn execute_repeatable<'c, T, U, E>(&self, txn: T) -> Result<U, Error>
where
// T: FnOnce(&'a mut Self::DbConnection<'_>) -> Fut,
// Fut: std::future::Future<Output = Result<U, E>> + Send + 'a,
T: for<'r> FnOnce(&'r mut Self::DbConnection<'_>) -> ScopedBoxFuture<'static, 'r, Result<U, E>> + Send + 'c,
T: for<'r> FnOnce(
&'r mut Self::DbConnection<'_>,
) -> ScopedBoxFuture<'static, 'r, Result<U, E>>
+ Send
+ 'c,
E: From<diesel::result::Error> + std::error::Error,
T: Send + 'static,
U: Send + 'static,
Expand Down
20 changes: 10 additions & 10 deletions crates/sui-graphql-rpc/src/data/pg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,17 +49,15 @@ impl QueryExecutor for PgExecutor {

async fn execute<'c, T, U, E>(&self, txn: T) -> Result<U, Error>
where
// T: FnOnce(&'a mut Self::DbConnection<'a>) -> Fut,
// Fut: std::future::Future<Output = Result<U, E>> + Send + 'a,
T: for<'r> FnOnce(&'r mut Self::DbConnection<'_>) -> ScopedBoxFuture<'static, 'r, Result<U, E>> + Send + 'c,
T: for<'r> FnOnce(
&'r mut Self::DbConnection<'_>,
) -> ScopedBoxFuture<'static, 'r, Result<U, E>>
+ Send
+ 'c,
E: From<diesel::result::Error> + std::error::Error,
T: Send + 'static,
U: Send + 'static,
E: Send + 'static,
// T: for<'r> FnOnce(&'r mut Self::DbConnection<'_>) -> ScopedBoxFuture<'b, 'r, Result<U, E>>
// + Send,
// U: 'b,
// E: From<diesel::result::Error> + std::error::Error + 'b,
{
let max_cost = self.limits.max_db_query_cost;
let instant = Instant::now();
Expand Down Expand Up @@ -92,9 +90,11 @@ impl QueryExecutor for PgExecutor {

async fn execute_repeatable<'c, T, U, E>(&self, txn: T) -> Result<U, Error>
where
// T: FnOnce(&'a mut Self::DbConnection<'_>) -> Fut,
// Fut: std::future::Future<Output = Result<U, E>> + Send + 'a,
T: for<'r> FnOnce(&'r mut Self::DbConnection<'_>) -> ScopedBoxFuture<'static, 'r, Result<U, E>> + Send + 'c,
T: for<'r> FnOnce(
&'r mut Self::DbConnection<'_>,
) -> ScopedBoxFuture<'static, 'r, Result<U, E>>
+ Send
+ 'c,
E: From<diesel::result::Error> + std::error::Error,
T: Send + 'static,
U: Send + 'static,
Expand Down
13 changes: 8 additions & 5 deletions crates/sui-graphql-rpc/src/types/chain_identifier.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,14 @@ impl ChainIdentifier {
use chain_identifier::dsl;

let Some(digest_bytes) = db
.execute(move |conn| async {
conn.first(move || dsl::chain_identifier.select(dsl::checkpoint_digest))
.await
.optional()
}.scope_boxed())
.execute(move |conn| {
async {
conn.first(move || dsl::chain_identifier.select(dsl::checkpoint_digest))
.await
.optional()
}
.scope_boxed()
})
.await
.map_err(|e| Error::Internal(format!("Failed to fetch genesis digest: {e}")))?
else {
Expand Down
4 changes: 2 additions & 2 deletions crates/sui-graphql-rpc/src/types/cursor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ use async_graphql::{
*,
};
use diesel::{
deserialize::FromSqlRow, query_builder::QueryFragment,
sql_types::Untyped, QueryDsl, QueryResult, QuerySource,
deserialize::FromSqlRow, query_builder::QueryFragment, sql_types::Untyped, QueryDsl,
QueryResult, QuerySource,
};
use diesel_async::methods::LoadQuery;
use fastcrypto::encoding::{Base64, Encoding};
Expand Down

0 comments on commit f8eb2ca

Please sign in to comment.