From 352862e945eb8e5e56d671542a7b459021c94336 Mon Sep 17 00:00:00 2001 From: Tim Diekmann <21277928+TimDiekmann@users.noreply.github.com> Date: Sat, 5 Oct 2024 15:10:47 +0200 Subject: [PATCH 1/7] Remove `async-trait` from `StoreMigration` --- .../libs/graph/src/store/migration.rs | 18 ++++++++++++------ .../libs/graph/src/store/postgres/migration.rs | 2 -- 2 files changed, 12 insertions(+), 8 deletions(-) diff --git a/apps/hash-graph/libs/graph/src/store/migration.rs b/apps/hash-graph/libs/graph/src/store/migration.rs index 9b9c7e0dde8..247351a6199 100644 --- a/apps/hash-graph/libs/graph/src/store/migration.rs +++ b/apps/hash-graph/libs/graph/src/store/migration.rs @@ -1,4 +1,3 @@ -use async_trait::async_trait; use error_stack::Result; use super::error::MigrationError; @@ -54,12 +53,19 @@ impl Migration { /// /// In addition to the errors described in the methods of this trait, further errors might also be /// raised depending on the implementation, e.g. connection issues. -#[async_trait] pub trait StoreMigration: Sync { - async fn run_migrations(&mut self) -> Result, MigrationError>; + fn run_migrations( + &mut self, + ) -> impl Future, MigrationError>> + Send; - async fn all_migrations(&mut self) -> Result, MigrationError>; + fn all_migrations( + &mut self, + ) -> impl Future, MigrationError>> + Send; - async fn applied_migrations(&mut self) -> Result, MigrationError>; - async fn missing_migrations(&mut self) -> Result, MigrationError>; + fn applied_migrations( + &mut self, + ) -> impl Future, MigrationError>> + Send; + fn missing_migrations( + &mut self, + ) -> impl Future, MigrationError>> + Send; } diff --git a/apps/hash-graph/libs/graph/src/store/postgres/migration.rs b/apps/hash-graph/libs/graph/src/store/postgres/migration.rs index 375ceed973d..d7ebdd14f82 100644 --- a/apps/hash-graph/libs/graph/src/store/postgres/migration.rs +++ b/apps/hash-graph/libs/graph/src/store/postgres/migration.rs @@ -1,4 +1,3 @@ -use async_trait::async_trait; use error_stack::{Result, ResultExt}; use tokio_postgres::Client; @@ -31,7 +30,6 @@ impl Migration { } } -#[async_trait] impl StoreMigration for PostgresStore where C: AsClient, From 1451ba4d2dbc7b32bd9aa1495026d56598a79eee Mon Sep 17 00:00:00 2001 From: Tim Diekmann <21277928+TimDiekmann@users.noreply.github.com> Date: Sat, 5 Oct 2024 15:12:26 +0200 Subject: [PATCH 2/7] Remove `async-trait` from `TypeFetcher` --- apps/hash-graph/libs/graph/src/store/fetcher.rs | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/apps/hash-graph/libs/graph/src/store/fetcher.rs b/apps/hash-graph/libs/graph/src/store/fetcher.rs index b712e454fcb..a2bd9bfaed9 100644 --- a/apps/hash-graph/libs/graph/src/store/fetcher.rs +++ b/apps/hash-graph/libs/graph/src/store/fetcher.rs @@ -2,7 +2,6 @@ use alloc::sync::Arc; use core::mem; use std::collections::{HashMap, HashSet}; -use async_trait::async_trait; use authorization::{ AuthorizationApi, schema::{ @@ -51,7 +50,7 @@ use crate::{ ontology::domain_validator::DomainValidator, store::{ DataTypeStore, EntityStore, EntityTypeStore, InsertionError, PropertyTypeStore, QueryError, - StoreError, StorePool, UpdateError, + StoreError, StorePool, UpdateError, async_trait, crud::{QueryResult, Read, ReadPaginated, Sorting}, knowledge::{ CountEntitiesParams, CreateEntityParams, GetEntitiesParams, GetEntitiesResponse, @@ -73,14 +72,13 @@ use crate::{ }, }; -#[async_trait] pub trait TypeFetcher { /// Fetches the provided type reference and inserts it to the Graph. - async fn insert_external_ontology_type( + fn insert_external_ontology_type( &mut self, actor_id: AccountId, reference: OntologyTypeReference<'_>, - ) -> Result; + ) -> impl Future> + Send; } #[derive(Clone)] @@ -675,7 +673,6 @@ where } } -#[async_trait] impl TypeFetcher for FetchingStore where A: ToSocketAddrs + Send + Sync, From 5a142a6fc2630d8a93f03c4cd189a570e0bf768b Mon Sep 17 00:00:00 2001 From: Tim Diekmann <21277928+TimDiekmann@users.noreply.github.com> Date: Sat, 5 Oct 2024 15:15:46 +0200 Subject: [PATCH 3/7] Remove `async-trait` from `WriteBatch` --- .../libs/graph/src/snapshot/entity/batch.rs | 2 -- apps/hash-graph/libs/graph/src/snapshot/mod.rs | 15 +++++++++------ .../src/snapshot/ontology/data_type/batch.rs | 2 -- .../src/snapshot/ontology/entity_type/batch.rs | 2 -- .../graph/src/snapshot/ontology/metadata/batch.rs | 2 -- .../src/snapshot/ontology/property_type/batch.rs | 2 -- .../libs/graph/src/snapshot/owner/batch.rs | 2 -- .../libs/graph/src/snapshot/restore/batch.rs | 2 -- .../libs/graph/src/snapshot/web/batch.rs | 2 -- 9 files changed, 9 insertions(+), 22 deletions(-) diff --git a/apps/hash-graph/libs/graph/src/snapshot/entity/batch.rs b/apps/hash-graph/libs/graph/src/snapshot/entity/batch.rs index 4e5f1e2d4dd..0679878961a 100644 --- a/apps/hash-graph/libs/graph/src/snapshot/entity/batch.rs +++ b/apps/hash-graph/libs/graph/src/snapshot/entity/batch.rs @@ -1,4 +1,3 @@ -use async_trait::async_trait; use authorization::{AuthorizationApi, backend::ZanzibarBackend, schema::EntityRelationAndSubject}; use error_stack::{Report, ResultExt}; use graph_types::{ @@ -36,7 +35,6 @@ pub enum EntityRowBatch { Relations(Vec<(EntityUuid, EntityRelationAndSubject)>), } -#[async_trait] impl WriteBatch for EntityRowBatch where C: AsClient, diff --git a/apps/hash-graph/libs/graph/src/snapshot/mod.rs b/apps/hash-graph/libs/graph/src/snapshot/mod.rs index c666a720729..e5c6c31746a 100644 --- a/apps/hash-graph/libs/graph/src/snapshot/mod.rs +++ b/apps/hash-graph/libs/graph/src/snapshot/mod.rs @@ -20,7 +20,6 @@ mod web; use core::future::ready; use async_scoped::TokioScope; -use async_trait::async_trait; use authorization::{ AuthorizationApi, NoAuthorization, backend::ZanzibarBackend, @@ -229,14 +228,18 @@ impl SnapshotEntry { } } -#[async_trait] trait WriteBatch { - async fn begin(postgres_client: &mut PostgresStore) -> Result<(), InsertionError>; - async fn write(self, postgres_client: &mut PostgresStore) -> Result<(), InsertionError>; - async fn commit( + fn begin( + postgres_client: &mut PostgresStore, + ) -> impl Future> + Send; + fn write( + self, + postgres_client: &mut PostgresStore, + ) -> impl Future> + Send; + fn commit( postgres_client: &mut PostgresStore, validation: bool, - ) -> Result<(), InsertionError>; + ) -> impl Future> + Send; } pub struct SnapshotStore(PostgresStore); diff --git a/apps/hash-graph/libs/graph/src/snapshot/ontology/data_type/batch.rs b/apps/hash-graph/libs/graph/src/snapshot/ontology/data_type/batch.rs index e6732c03d5e..a6a4ca56f37 100644 --- a/apps/hash-graph/libs/graph/src/snapshot/ontology/data_type/batch.rs +++ b/apps/hash-graph/libs/graph/src/snapshot/ontology/data_type/batch.rs @@ -1,6 +1,5 @@ use std::collections::HashMap; -use async_trait::async_trait; use authorization::{ AuthorizationApi, backend::ZanzibarBackend, schema::DataTypeRelationAndSubject, }; @@ -23,7 +22,6 @@ pub enum DataTypeRowBatch { Embeddings(Vec>), } -#[async_trait] impl WriteBatch for DataTypeRowBatch where C: AsClient, diff --git a/apps/hash-graph/libs/graph/src/snapshot/ontology/entity_type/batch.rs b/apps/hash-graph/libs/graph/src/snapshot/ontology/entity_type/batch.rs index 33fdadc0d45..d1c68619509 100644 --- a/apps/hash-graph/libs/graph/src/snapshot/ontology/entity_type/batch.rs +++ b/apps/hash-graph/libs/graph/src/snapshot/ontology/entity_type/batch.rs @@ -1,6 +1,5 @@ use std::collections::HashMap; -use async_trait::async_trait; use authorization::{ AuthorizationApi, backend::ZanzibarBackend, schema::EntityTypeRelationAndSubject, }; @@ -33,7 +32,6 @@ pub enum EntityTypeRowBatch { Embeddings(Vec>), } -#[async_trait] impl WriteBatch for EntityTypeRowBatch where C: AsClient, diff --git a/apps/hash-graph/libs/graph/src/snapshot/ontology/metadata/batch.rs b/apps/hash-graph/libs/graph/src/snapshot/ontology/metadata/batch.rs index ab2a174ce4d..90e62af6e3a 100644 --- a/apps/hash-graph/libs/graph/src/snapshot/ontology/metadata/batch.rs +++ b/apps/hash-graph/libs/graph/src/snapshot/ontology/metadata/batch.rs @@ -1,4 +1,3 @@ -use async_trait::async_trait; use error_stack::{Result, ResultExt}; use tokio_postgres::GenericClient; @@ -20,7 +19,6 @@ pub enum OntologyTypeMetadataRowBatch { ExternalMetadata(Vec), } -#[async_trait] impl WriteBatch for OntologyTypeMetadataRowBatch where C: AsClient, diff --git a/apps/hash-graph/libs/graph/src/snapshot/ontology/property_type/batch.rs b/apps/hash-graph/libs/graph/src/snapshot/ontology/property_type/batch.rs index 5ced52c9e92..3bef38a66e2 100644 --- a/apps/hash-graph/libs/graph/src/snapshot/ontology/property_type/batch.rs +++ b/apps/hash-graph/libs/graph/src/snapshot/ontology/property_type/batch.rs @@ -1,6 +1,5 @@ use std::collections::HashMap; -use async_trait::async_trait; use authorization::{backend::ZanzibarBackend, schema::PropertyTypeRelationAndSubject}; use error_stack::{Result, ResultExt}; use graph_types::ontology::PropertyTypeId; @@ -25,7 +24,6 @@ pub enum PropertyTypeRowBatch { Embeddings(Vec>), } -#[async_trait] impl WriteBatch for PropertyTypeRowBatch where C: AsClient, diff --git a/apps/hash-graph/libs/graph/src/snapshot/owner/batch.rs b/apps/hash-graph/libs/graph/src/snapshot/owner/batch.rs index f5c9b9edb2f..9526acccd35 100644 --- a/apps/hash-graph/libs/graph/src/snapshot/owner/batch.rs +++ b/apps/hash-graph/libs/graph/src/snapshot/owner/batch.rs @@ -1,4 +1,3 @@ -use async_trait::async_trait; use authorization::{backend::ZanzibarBackend, schema::AccountGroupRelationAndSubject}; use error_stack::{Result, ResultExt}; use graph_types::account::AccountGroupId; @@ -18,7 +17,6 @@ pub enum AccountRowBatch { AccountGroupAccountRelations(Vec<(AccountGroupId, AccountGroupRelationAndSubject)>), } -#[async_trait] impl WriteBatch for AccountRowBatch where C: AsClient, diff --git a/apps/hash-graph/libs/graph/src/snapshot/restore/batch.rs b/apps/hash-graph/libs/graph/src/snapshot/restore/batch.rs index d02b8157897..306da77412a 100644 --- a/apps/hash-graph/libs/graph/src/snapshot/restore/batch.rs +++ b/apps/hash-graph/libs/graph/src/snapshot/restore/batch.rs @@ -1,4 +1,3 @@ -use async_trait::async_trait; use authorization::{AuthorizationApi, backend::ZanzibarBackend}; use error_stack::Result; @@ -26,7 +25,6 @@ pub enum SnapshotRecordBatch { Entities(EntityRowBatch), } -#[async_trait] impl WriteBatch for SnapshotRecordBatch where C: AsClient, diff --git a/apps/hash-graph/libs/graph/src/snapshot/web/batch.rs b/apps/hash-graph/libs/graph/src/snapshot/web/batch.rs index f075cf9b01d..c93de8a3671 100644 --- a/apps/hash-graph/libs/graph/src/snapshot/web/batch.rs +++ b/apps/hash-graph/libs/graph/src/snapshot/web/batch.rs @@ -1,4 +1,3 @@ -use async_trait::async_trait; use authorization::{backend::ZanzibarBackend, schema::WebRelationAndSubject}; use error_stack::{Result, ResultExt}; use graph_types::owned_by_id::OwnedById; @@ -14,7 +13,6 @@ pub enum WebBatch { Relations(Vec<(OwnedById, WebRelationAndSubject)>), } -#[async_trait] impl WriteBatch for WebBatch where C: AsClient, From a2d6fdfa368a1f9db9593560953e4e7dded78b12 Mon Sep 17 00:00:00 2001 From: Tim Diekmann <21277928+TimDiekmann@users.noreply.github.com> Date: Sat, 5 Oct 2024 15:59:33 +0200 Subject: [PATCH 4/7] Remove `async-trait` from `Store` --- apps/hash-graph/libs/graph/src/store/fetcher.rs | 3 ++- apps/hash-graph/libs/graph/src/store/mod.rs | 3 +-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/apps/hash-graph/libs/graph/src/store/fetcher.rs b/apps/hash-graph/libs/graph/src/store/fetcher.rs index a2bd9bfaed9..11842b286ec 100644 --- a/apps/hash-graph/libs/graph/src/store/fetcher.rs +++ b/apps/hash-graph/libs/graph/src/store/fetcher.rs @@ -2,6 +2,7 @@ use alloc::sync::Arc; use core::mem; use std::collections::{HashMap, HashSet}; +use async_trait::async_trait; use authorization::{ AuthorizationApi, schema::{ @@ -50,7 +51,7 @@ use crate::{ ontology::domain_validator::DomainValidator, store::{ DataTypeStore, EntityStore, EntityTypeStore, InsertionError, PropertyTypeStore, QueryError, - StoreError, StorePool, UpdateError, async_trait, + StoreError, StorePool, UpdateError, crud::{QueryResult, Read, ReadPaginated, Sorting}, knowledge::{ CountEntitiesParams, CreateEntityParams, GetEntitiesParams, GetEntitiesResponse, diff --git a/apps/hash-graph/libs/graph/src/store/mod.rs b/apps/hash-graph/libs/graph/src/store/mod.rs index 88d978cc7bc..9f94848cb82 100644 --- a/apps/hash-graph/libs/graph/src/store/mod.rs +++ b/apps/hash-graph/libs/graph/src/store/mod.rs @@ -11,7 +11,6 @@ mod validation; mod fetcher; pub(crate) mod postgres; -use async_trait::async_trait; use hash_graph_store::account::AccountStore; use serde::Deserialize; #[cfg(feature = "utoipa")] @@ -41,11 +40,11 @@ pub use self::{ /// /// In addition to the errors described in the methods of this trait, further errors might also be /// raised depending on the implementation, e.g. connection issues. -#[async_trait] pub trait Store: AccountStore + DataTypeStore + PropertyTypeStore + EntityTypeStore + EntityStore { } + impl Store for S where S: AccountStore + DataTypeStore + PropertyTypeStore + EntityTypeStore + EntityStore { From d3cea6f77c66a2f06faeee179f831d5b5b20f3f9 Mon Sep 17 00:00:00 2001 From: Tim Diekmann <21277928+TimDiekmann@users.noreply.github.com> Date: Sat, 5 Oct 2024 16:00:15 +0200 Subject: [PATCH 5/7] Remove `async-trait` from `RestApiStore` --- apps/hash-graph/libs/api/src/rest/mod.rs | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/apps/hash-graph/libs/api/src/rest/mod.rs b/apps/hash-graph/libs/api/src/rest/mod.rs index 7704c4dcb5d..956761aeb92 100644 --- a/apps/hash-graph/libs/api/src/rest/mod.rs +++ b/apps/hash-graph/libs/api/src/rest/mod.rs @@ -120,17 +120,16 @@ impl FromRequestParts for AuthenticatedUserHeader { pub struct PermissionResponse { has_permission: bool, } -#[async_trait] + pub trait RestApiStore: Store + TypeFetcher { - async fn load_external_type( + fn load_external_type( &mut self, actor_id: AccountId, domain_validator: &DomainValidator, reference: OntologyTypeReference<'_>, - ) -> Result; + ) -> impl Future> + Send; } -#[async_trait] impl RestApiStore for S where S: Store + TypeFetcher + Send, From f69fb302ca05fca553d85d5ce9c7ceb3b0266bfe Mon Sep 17 00:00:00 2001 From: Tim Diekmann <21277928+TimDiekmann@users.noreply.github.com> Date: Sat, 5 Oct 2024 16:07:35 +0200 Subject: [PATCH 6/7] Remove `async-trait` from `Read` --- apps/hash-graph/libs/graph/src/store/crud.rs | 20 ++++++++----------- .../libs/graph/src/store/fetcher.rs | 2 -- .../libs/graph/src/store/postgres/crud.rs | 2 -- .../store/postgres/knowledge/entity/mod.rs | 5 ++++- 4 files changed, 12 insertions(+), 17 deletions(-) diff --git a/apps/hash-graph/libs/graph/src/store/crud.rs b/apps/hash-graph/libs/graph/src/store/crud.rs index cf298fa04d8..40a52a0f0ac 100644 --- a/apps/hash-graph/libs/graph/src/store/crud.rs +++ b/apps/hash-graph/libs/graph/src/store/crud.rs @@ -6,9 +6,8 @@ //! //! [`Store`]: crate::store::Store -use async_trait::async_trait; use error_stack::Result; -use futures::{Stream, TryStreamExt}; +use futures::{Stream, TryFutureExt, TryStreamExt}; use hash_graph_store::{ filter::{Filter, QueryRecord}, subgraph::{SubgraphRecord, temporal_axes::QueryTemporalAxes}, @@ -202,36 +201,33 @@ pub trait ReadPaginated: Read { /// Read access to a [`Store`]. /// /// [`Store`]: crate::store::Store -#[async_trait] pub trait Read: Sync { type ReadStream: Stream> + Send + Sync; - async fn read( + fn read( &self, filter: &Filter<'_, R>, temporal_axes: Option<&QueryTemporalAxes>, include_drafts: bool, - ) -> Result; + ) -> impl Future> + Send; #[instrument(level = "info", skip(self, filter))] - async fn read_vec( + fn read_vec( &self, filter: &Filter<'_, R>, temporal_axes: Option<&QueryTemporalAxes>, include_drafts: bool, - ) -> Result, QueryError> { + ) -> impl Future, QueryError>> + Send { self.read(filter, temporal_axes, include_drafts) - .await? - .try_collect() - .await + .and_then(TryStreamExt::try_collect) } - async fn read_one( + fn read_one( &self, filter: &Filter<'_, R>, temporal_axes: Option<&QueryTemporalAxes>, include_drafts: bool, - ) -> Result; + ) -> impl Future> + Send; } // TODO: Add remaining CRUD traits diff --git a/apps/hash-graph/libs/graph/src/store/fetcher.rs b/apps/hash-graph/libs/graph/src/store/fetcher.rs index 11842b286ec..4752631db1b 100644 --- a/apps/hash-graph/libs/graph/src/store/fetcher.rs +++ b/apps/hash-graph/libs/graph/src/store/fetcher.rs @@ -2,7 +2,6 @@ use alloc::sync::Arc; use core::mem; use std::collections::{HashMap, HashSet}; -use async_trait::async_trait; use authorization::{ AuthorizationApi, schema::{ @@ -738,7 +737,6 @@ where } } -#[async_trait] impl Read for FetchingStore where A: Send + Sync, diff --git a/apps/hash-graph/libs/graph/src/store/postgres/crud.rs b/apps/hash-graph/libs/graph/src/store/postgres/crud.rs index daa594bb489..eda9d571c93 100644 --- a/apps/hash-graph/libs/graph/src/store/postgres/crud.rs +++ b/apps/hash-graph/libs/graph/src/store/postgres/crud.rs @@ -1,4 +1,3 @@ -use async_trait::async_trait; use error_stack::{Report, ResultExt}; use futures::{Stream, StreamExt, TryStreamExt}; use hash_graph_store::{filter::Filter, subgraph::temporal_axes::QueryTemporalAxes}; @@ -99,7 +98,6 @@ where } } -#[async_trait] impl Read for PostgresStore where Cl: AsClient, diff --git a/apps/hash-graph/libs/graph/src/store/postgres/knowledge/entity/mod.rs b/apps/hash-graph/libs/graph/src/store/postgres/knowledge/entity/mod.rs index dd34860a618..affa85a5ebb 100644 --- a/apps/hash-graph/libs/graph/src/store/postgres/knowledge/entity/mod.rs +++ b/apps/hash-graph/libs/graph/src/store/postgres/knowledge/entity/mod.rs @@ -513,7 +513,10 @@ where let num_returned_entities = entities.len(); let (permitted_ids, zookie) = if let Some((permitted_ids, zookie)) = &permissions { - (Cow::Borrowed(permitted_ids), Cow::Borrowed(zookie)) + ( + Cow::>::Borrowed(permitted_ids), + Cow::::Borrowed(zookie), + ) } else { // TODO: The subgraph structure differs from the API interface. At the API the // vertices are stored in a nested `HashMap` and here it's flattened. We need From d14356382e4f0b8edbf2a848f39e2852f711155d Mon Sep 17 00:00:00 2001 From: Tim Diekmann <21277928+TimDiekmann@users.noreply.github.com> Date: Sat, 5 Oct 2024 16:09:28 +0200 Subject: [PATCH 7/7] Remove `async-trait` dependency from `graph` --- Cargo.lock | 1 - apps/hash-graph/libs/graph/Cargo.toml | 1 - 2 files changed, 2 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 488cba3c425..16277951435 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2383,7 +2383,6 @@ name = "graph" version = "0.0.0" dependencies = [ "async-scoped", - "async-trait", "authorization", "bytes", "clap", diff --git a/apps/hash-graph/libs/graph/Cargo.toml b/apps/hash-graph/libs/graph/Cargo.toml index f8a85154a64..498590d33ad 100644 --- a/apps/hash-graph/libs/graph/Cargo.toml +++ b/apps/hash-graph/libs/graph/Cargo.toml @@ -34,7 +34,6 @@ type-system = { workspace = true, features = ["postgres"] } # Private third-party dependencies async-scoped = { workspace = true, features = ["use-tokio"] } -async-trait = { workspace = true } bytes = { workspace = true } clap = { workspace = true, features = ["derive", "env"], optional = true } derive-where = { workspace = true }