Skip to content

Commit

Permalink
undo this commit
Browse files Browse the repository at this point in the history
  • Loading branch information
SimonThormeyer committed Oct 8, 2024
1 parent 6470f4a commit 2f0f8a7
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 10 deletions.
30 changes: 30 additions & 0 deletions keystore/src/connection/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,36 @@ impl Connection {
};
transaction.child_groups(entity, persisted_records).await
}

pub async fn save<E: Entity<ConnectionType = KeystoreDatabaseConnection> + Sync + EntityTransactionExt>(
&self,
entity: E,
) -> CryptoKeystoreResult<E> {
let transaction_guard = self.transaction.lock().await;
let Some(transaction) = transaction_guard.as_ref() else {
return Err(CryptoKeystoreError::MutatingOperationWithoutTransaction);
};
transaction.save_mut(entity).await
}

pub async fn insert<E: Entity<ConnectionType = KeystoreDatabaseConnection> + std::marker::Sync>(
&self,
entity: E,
) -> CryptoKeystoreResult<E::AutoGeneratedFields> {
let mut conn = self.conn.lock().await;
let fields = entity.insert(&mut conn).await?;

Check failure on line 210 in keystore/src/connection/mod.rs

View workflow job for this annotation

GitHub Actions / wasm-build (keystore)

no method named `insert` found for type parameter `E` in the current scope

Check failure on line 210 in keystore/src/connection/mod.rs

View workflow job for this annotation

GitHub Actions / wasm-build (crypto)

no method named `insert` found for type parameter `E` in the current scope

Check failure on line 210 in keystore/src/connection/mod.rs

View workflow job for this annotation

GitHub Actions / wasm-build (mls-provider)

no method named `insert` found for type parameter `E` in the current scope

Check failure on line 210 in keystore/src/connection/mod.rs

View workflow job for this annotation

GitHub Actions / wasm-test (mls-provider)

no method named `insert` found for type parameter `E` in the current scope

Check failure on line 210 in keystore/src/connection/mod.rs

View workflow job for this annotation

GitHub Actions / wasm-test (keystore)

no method named `insert` found for type parameter `E` in the current scope

Check failure on line 210 in keystore/src/connection/mod.rs

View workflow job for this annotation

GitHub Actions / proteus-wasm-test

no method named `insert` found for type parameter `E` in the current scope

Check failure on line 210 in keystore/src/connection/mod.rs

View workflow job for this annotation

GitHub Actions / hack

no method named `insert` found for type parameter `E` in the current scope

Check failure on line 210 in keystore/src/connection/mod.rs

View workflow job for this annotation

GitHub Actions / doc

no method named `insert` found for type parameter `E` in the current scope

Check failure on line 210 in keystore/src/connection/mod.rs

View workflow job for this annotation

GitHub Actions / build-android

no method named `insert` found for type parameter `E` in the current scope

Check failure on line 210 in keystore/src/connection/mod.rs

View workflow job for this annotation

GitHub Actions / build

no method named `insert` found for type parameter `E` in the current scope

Check failure on line 210 in keystore/src/connection/mod.rs

View workflow job for this annotation

GitHub Actions / Benchmark with Bencher

no method named `insert` found for type parameter `E` in the current scope

Check failure on line 210 in keystore/src/connection/mod.rs

View workflow job for this annotation

GitHub Actions / e2e-interop-test

no method named `insert` found for type parameter `E` in the current scope

Check failure on line 210 in keystore/src/connection/mod.rs

View workflow job for this annotation

GitHub Actions / test

no method named `insert` found for type parameter `E` in the current scope

Check failure on line 210 in keystore/src/connection/mod.rs

View workflow job for this annotation

GitHub Actions / coverage

no method named `insert` found for type parameter `E` in the current scope

Check failure on line 210 in keystore/src/connection/mod.rs

View workflow job for this annotation

GitHub Actions / proteus-test

no method named `insert` found for type parameter `E` in the current scope

Check failure on line 210 in keystore/src/connection/mod.rs

View workflow job for this annotation

GitHub Actions / test-keystore-regressions

no method named `insert` found for type parameter `E` in the current scope

Check failure on line 210 in keystore/src/connection/mod.rs

View workflow job for this annotation

GitHub Actions / build-swift

no method named `insert` found for type parameter `E` in the current scope
Ok(fields)
}

pub async fn remove<E: Entity<ConnectionType = KeystoreDatabaseConnection>, S: AsRef<[u8]>>(
&self,
id: S,
) -> CryptoKeystoreResult<()> {
let mut conn = self.conn.lock().await;
E::delete(&mut conn, id.as_ref().into()).await?;

Check failure on line 219 in keystore/src/connection/mod.rs

View workflow job for this annotation

GitHub Actions / hack

no function or associated item named `delete` found for type parameter `E` in the current scope

Check failure on line 219 in keystore/src/connection/mod.rs

View workflow job for this annotation

GitHub Actions / doc

no function or associated item named `delete` found for type parameter `E` in the current scope

Check failure on line 219 in keystore/src/connection/mod.rs

View workflow job for this annotation

GitHub Actions / build-android

no function or associated item named `delete` found for type parameter `E` in the current scope

Check failure on line 219 in keystore/src/connection/mod.rs

View workflow job for this annotation

GitHub Actions / build

no function or associated item named `delete` found for type parameter `E` in the current scope

Check failure on line 219 in keystore/src/connection/mod.rs

View workflow job for this annotation

GitHub Actions / Benchmark with Bencher

no function or associated item named `delete` found for type parameter `E` in the current scope

Check failure on line 219 in keystore/src/connection/mod.rs

View workflow job for this annotation

GitHub Actions / e2e-interop-test

no function or associated item named `delete` found for type parameter `E` in the current scope

Check failure on line 219 in keystore/src/connection/mod.rs

View workflow job for this annotation

GitHub Actions / test

no function or associated item named `delete` found for type parameter `E` in the current scope

Check failure on line 219 in keystore/src/connection/mod.rs

View workflow job for this annotation

GitHub Actions / coverage

no function or associated item named `delete` found for type parameter `E` in the current scope

Check failure on line 219 in keystore/src/connection/mod.rs

View workflow job for this annotation

GitHub Actions / proteus-test

no function or associated item named `delete` found for type parameter `E` in the current scope

Check failure on line 219 in keystore/src/connection/mod.rs

View workflow job for this annotation

GitHub Actions / test-keystore-regressions

no function or associated item named `delete` found for type parameter `E` in the current scope

Check failure on line 219 in keystore/src/connection/mod.rs

View workflow job for this annotation

GitHub Actions / build-swift

no function or associated item named `delete` found for type parameter `E` in the current scope
Ok(())
}

}

#[cfg_attr(target_family = "wasm", async_trait::async_trait(?Send))]
Expand Down
2 changes: 2 additions & 0 deletions keystore/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,8 @@ pub enum CryptoKeystoreError {
MissingKeyInStore(#[from] MissingKeyErrorKind),
#[error("The given key doesn't contain valid utf-8")]
KeyReprError(#[from] std::str::Utf8Error),
#[error("A transaction must be in progress to perform this operation.")]
MutatingOperationWithoutTransaction,
#[error("A transaction is already in progress.")]
TransactionInProgress,
#[error(transparent)]
Expand Down
10 changes: 0 additions & 10 deletions keystore/src/transaction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -235,15 +235,6 @@ impl KeystoreTransaction {
let cached_records: Vec<E> = self.cache.find_many(ids).await?;
Ok(Self::merge_records(cached_records, persisted_records, EntityFindParams::default()))
}

pub(crate) async fn count<E: crate::entities::Entity<ConnectionType = KeystoreDatabaseConnection>>(
&self,
persisted_records: Vec<E>,
) -> CryptoKeystoreResult<usize> {
// Unfortunately, we have to do this. We cannot just add the counts of the cache and the db
// because of possible record id overlap between cache and db.
Ok(self.find_all::<E>(persisted_records, Default::default()).await?.len())
}

fn merge_records<E: crate::entities::Entity<ConnectionType = KeystoreDatabaseConnection>>(records_a: Vec<E>, records_b: Vec<E>, params: EntityFindParams) -> Vec<E> {
let merged = records_a
Expand Down Expand Up @@ -340,7 +331,6 @@ impl KeystoreTransaction {
&self,
mut entity: E,
) -> CryptoKeystoreResult<E> {
// If transaction is some, save entity there, otherwise throw error
entity.pre_save().await?;
let mut conn = self.cache.borrow_conn().await?;
let transaction = conn.new_transaction().await?;

Check failure on line 336 in keystore/src/transaction.rs

View workflow job for this annotation

GitHub Actions / wasm-build (keystore)

this method takes 1 argument but 0 arguments were supplied

Check failure on line 336 in keystore/src/transaction.rs

View workflow job for this annotation

GitHub Actions / wasm-build (crypto)

this method takes 1 argument but 0 arguments were supplied

Check failure on line 336 in keystore/src/transaction.rs

View workflow job for this annotation

GitHub Actions / wasm-build (mls-provider)

this method takes 1 argument but 0 arguments were supplied

Check failure on line 336 in keystore/src/transaction.rs

View workflow job for this annotation

GitHub Actions / wasm-test (mls-provider)

this method takes 1 argument but 0 arguments were supplied

Check failure on line 336 in keystore/src/transaction.rs

View workflow job for this annotation

GitHub Actions / wasm-test (keystore)

this method takes 1 argument but 0 arguments were supplied

Check failure on line 336 in keystore/src/transaction.rs

View workflow job for this annotation

GitHub Actions / proteus-wasm-test

this method takes 1 argument but 0 arguments were supplied
Expand Down

0 comments on commit 2f0f8a7

Please sign in to comment.