Skip to content

Commit

Permalink
List manifest return manifest data struct
Browse files Browse the repository at this point in the history
  • Loading branch information
FirelightFlagboy committed Jul 31, 2024
1 parent 98ff323 commit 82fd43f
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 9 deletions.
4 changes: 4 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,8 @@ sha2 = { version = "0.10.8", default-features = false }
sharks = "0.5.0"
sodiumoxide = { version = "0.2.7", default-features = false }
sqlx = { version = "0.7.2", default-features = false }
sqlx-core = { version = "0.7.2", default-features = false }
sqlx-sqlite = { version = "0.7.2", default-features = false }
syn = { version = "2.0.72", default-features = false }
spinners = { version = "4.1.1", default-features = false }
thiserror = { version = "1.0.63", default-features = false }
Expand Down
2 changes: 2 additions & 0 deletions libparsec/crates/platform_storage/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ tokio = { workspace = true, features = ["fs", "sync"] }
# We add this dependency to have sqlite3 bundled into our code.
libsqlite3-sys = { workspace = true, features = ["bundled"] }
sqlx = { workspace = true, features = ["sqlite", "runtime-tokio", "macros"] }
sqlx-core = { workspace = true, features = ["uuid"] }
sqlx-sqlite = { workspace = true, features = ["uuid"] }

[target.'cfg(target_arch = "wasm32")'.dependencies]
indexed_db_futures = { workspace = true, features = ["indices", "cursors"] }
Expand Down
29 changes: 21 additions & 8 deletions libparsec/crates/platform_storage/src/native/workspace.rs
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ impl PlatformWorkspaceStorage {
&mut self,
page: u32,
limit: u32,
) -> anyhow::Result<Vec<RawEncryptedManifest>> {
) -> anyhow::Result<Vec<ManifestData>> {
db_list_manifests(&mut self.conn, page, limit).await
}

Expand Down Expand Up @@ -654,18 +654,31 @@ async fn db_list_manifests(
executor: impl sqlx::Executor<'_, Database = sqlx::Sqlite>,
page: u32,
limit: u32,
) -> anyhow::Result<Vec<RawEncryptedManifest>> {
) -> anyhow::Result<Vec<ManifestData>> {
let offset = page * limit;
let rows = sqlx::query("SELECT blob FROM vlobs LIMIT ?1 OFFSET ?2")
.bind(limit)
.bind(offset)
.fetch_many(executor);
let rows =
sqlx::query("SELECT vlob_id, blob, need_sync, base_version FROM vlobs LIMIT ?1 OFFSET ?2")
.bind(limit)
.bind(offset)
.fetch_many(executor);

fn row_to_manifest_data(row: sqlx::sqlite::SqliteRow) -> anyhow::Result<ManifestData> {
Ok(ManifestData {
entry_id: row
.try_get::<sqlx::types::Uuid, usize>(0)
.map(VlobID::from)
.map_err(anyhow::Error::from)?,
encrypted: row.try_get(1).map_err(anyhow::Error::from)?,
need_sync: row.try_get(2).map_err(anyhow::Error::from)?,
base_version: row.try_get(3).map_err(anyhow::Error::from)?,
})
}

let res: anyhow::Result<Vec<RawEncryptedManifest>> = rows
let res: anyhow::Result<Vec<ManifestData>> = rows
.filter_map(|row_res| async {
match row_res {
Ok(sqlx::Either::Left(_res)) => None,
Ok(sqlx::Either::Right(row)) => Some(row.try_get(0).map_err(anyhow::Error::from)),
Ok(sqlx::Either::Right(row)) => Some(row_to_manifest_data(row)),
Err(e) => Some(Err(e.into())),
}
})
Expand Down
2 changes: 1 addition & 1 deletion libparsec/crates/platform_storage/src/workspace.rs
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ impl WorkspaceStorage {
&mut self,
page: u32,
limit: u32,
) -> anyhow::Result<Vec<RawEncryptedManifest>> {
) -> anyhow::Result<Vec<ManifestData>> {
self.platform.list_manifests(page, limit).await

Check failure on line 150 in libparsec/crates/platform_storage/src/workspace.rs

View workflow job for this annotation

GitHub Actions / web / 🌐 Web tests

mismatched types
}

Expand Down

0 comments on commit 82fd43f

Please sign in to comment.