Skip to content

Commit edd9f1f

Browse files
committed
feat: improve data struct in store for saving storage space
1 parent b2b8299 commit edd9f1f

File tree

12 files changed

+75
-135
lines changed

12 files changed

+75
-135
lines changed

Cargo.lock

Lines changed: 6 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ strip = true
1717
opt-level = 's'
1818

1919
[workspace.package]
20-
version = "0.7.4"
20+
version = "0.8.0"
2121
edition = "2021"
2222
repository = "https://github.com/ldclabs/ic-oss"
2323
keywords = ["file", "storage", "oss", "s3", "icp"]

examples/ai_canister/Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,5 +19,5 @@ serde = { workspace = true }
1919
serde_bytes = { workspace = true }
2020
getrandom = { workspace = true }
2121
rand = { version = "0.8", features = ["getrandom"] }
22-
ic-oss-types = { path = "../../src/ic_oss_types", version = "0.7" }
23-
ic-oss-can = { path = "../../src/ic_oss_can", version = "0.7" }
22+
ic-oss-types = { path = "../../src/ic_oss_types", version = "0.8" }
23+
ic-oss-can = { path = "../../src/ic_oss_can", version = "0.8" }

src/ic_oss/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,4 +20,4 @@ tokio-stream = { workspace = true }
2020
futures = { workspace = true }
2121
sha3 = { workspace = true }
2222
ic-agent = "0.36"
23-
ic-oss-types = { path = "../ic_oss_types", version = "0.7" }
23+
ic-oss-types = { path = "../ic_oss_types", version = "0.8" }

src/ic_oss_bucket/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,4 +28,4 @@ ic-http-certification = { workspace = true }
2828
getrandom = { workspace = true }
2929
lazy_static = "1.4"
3030
hyperx = { git = "https://github.com/ldclabs/hyperx", rev = "4b9bd373b8c4d29a32e59912bf598ba69273c032" }
31-
ic-oss-types = { path = "../ic_oss_types", version = "0.7" }
31+
ic-oss-types = { path = "../ic_oss_types", version = "0.8" }

src/ic_oss_bucket/src/store.rs

Lines changed: 39 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -35,22 +35,36 @@ static ZERO_HASH: [u8; 32] = [0; 32];
3535

3636
#[derive(Clone, Deserialize, Serialize)]
3737
pub struct Bucket {
38+
#[serde(rename = "n", alias = "name")]
3839
pub name: String,
40+
#[serde(rename = "fi", alias = "file_id")]
3941
pub file_id: u32,
42+
#[serde(rename = "fo", alias = "folder_id")]
4043
pub folder_id: u32,
44+
#[serde(rename = "fz", alias = "max_file_size")]
4145
pub max_file_size: u64,
46+
#[serde(rename = "fd", alias = "max_folder_depth")]
4247
pub max_folder_depth: u8,
48+
#[serde(rename = "mc", alias = "max_children")]
4349
pub max_children: u16,
50+
#[serde(rename = "cds", alias = "max_custom_data_size")]
4451
pub max_custom_data_size: u16,
52+
#[serde(rename = "h", alias = "enable_hash_index")]
4553
pub enable_hash_index: bool,
46-
pub status: i8, // -1: archived; 0: readable and writable; 1: readonly
54+
#[serde(rename = "s", alias = "status")]
55+
pub status: i8, // -1: archived; 0: readable and writable; 1: readonly
56+
#[serde(rename = "v", alias = "visibility")]
4757
pub visibility: u8, // 0: private; 1: public
58+
#[serde(rename = "m", alias = "managers")]
4859
pub managers: BTreeSet<Principal>, // managers can read and write
4960
// auditors can read and list even if the bucket is private
61+
#[serde(rename = "a", alias = "auditors")]
5062
pub auditors: BTreeSet<Principal>,
5163
// used to verify the request token signed with SECP256K1
64+
#[serde(rename = "ec", alias = "trusted_ecdsa_pub_keys")]
5265
pub trusted_ecdsa_pub_keys: Vec<ByteBuf>,
5366
// used to verify the request token signed with ED25519
67+
#[serde(rename = "ed", alias = "trusted_eddsa_pub_keys")]
5468
pub trusted_eddsa_pub_keys: Vec<ByteArray<32>>,
5569
}
5670

@@ -224,18 +238,31 @@ impl Storable for FileId {
224238

225239
#[derive(Clone, Default, Deserialize, Serialize)]
226240
pub struct FileMetadata {
241+
#[serde(rename = "p", alias = "parent")]
227242
pub parent: u32, // 0: root
243+
#[serde(rename = "n", alias = "name")]
228244
pub name: String,
245+
#[serde(rename = "t", alias = "content_type")]
229246
pub content_type: String, // MIME types
247+
#[serde(rename = "i", alias = "size")]
230248
pub size: u64,
249+
#[serde(rename = "f", alias = "filled")]
231250
pub filled: u64,
251+
#[serde(rename = "ca", alias = "created_at")]
232252
pub created_at: u64, // unix timestamp in milliseconds
253+
#[serde(rename = "ua", alias = "updated_at")]
233254
pub updated_at: u64, // unix timestamp in milliseconds
255+
#[serde(rename = "c", alias = "chunks")]
234256
pub chunks: u32,
257+
#[serde(rename = "s", alias = "status")]
235258
pub status: i8, // -1: archived; 0: readable and writable; 1: readonly
259+
#[serde(rename = "h", alias = "hash")]
236260
pub hash: Option<ByteArray<32>>, // recommend sha3 256
261+
#[serde(rename = "k", alias = "dek")]
237262
pub dek: Option<ByteBuf>, // // Data Encryption Key that encrypted by BYOK or vetKey in COSE_Encrypt0
263+
#[serde(rename = "cu", alias = "custom")]
238264
pub custom: Option<MapValue>, // custom metadata
265+
#[serde(rename = "e", alias = "ex")]
239266
pub ex: Option<MapValue>, // External Resource, ER indicates that the file is an external resource.
240267
}
241268

@@ -295,13 +322,20 @@ impl Storable for Chunk {
295322
// folder
296323
#[derive(Clone, Debug, Default, Deserialize, Serialize)]
297324
pub struct FolderMetadata {
325+
#[serde(rename = "p", alias = "parent")]
298326
pub parent: u32, // 0: root
327+
#[serde(rename = "n", alias = "name")]
299328
pub name: String,
300-
pub files: BTreeSet<u32>, // length <= max_children
329+
#[serde(rename = "fi", alias = "files")]
330+
pub files: BTreeSet<u32>, // length <= max_children
331+
#[serde(rename = "fo", alias = "folders")]
301332
pub folders: BTreeSet<u32>, // length <= max_children
302-
pub created_at: u64, // unix timestamp in milliseconds
303-
pub updated_at: u64, // unix timestamp in milliseconds
304-
pub status: i8, // -1: archived; 0: readable and writable; 1: readonly
333+
#[serde(rename = "ca", alias = "created_at")]
334+
pub created_at: u64, // unix timestamp in milliseconds
335+
#[serde(rename = "ua", alias = "updated_at")]
336+
pub updated_at: u64, // unix timestamp in milliseconds
337+
#[serde(rename = "s", alias = "status")]
338+
pub status: i8, // -1: archived; 0: readable and writable; 1: readonly
305339
}
306340

307341
impl FolderMetadata {

src/ic_oss_can/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,4 @@ serde_bytes = { workspace = true }
1616
ciborium = { workspace = true }
1717
ic-cdk = { workspace = true }
1818
ic-stable-structures = { workspace = true }
19-
ic-oss-types = { path = "../ic_oss_types", version = "0.7" }
19+
ic-oss-types = { path = "../ic_oss_types", version = "0.8" }

src/ic_oss_cli/Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@ serde_bytes = { workspace = true }
1515
tokio = { workspace = true }
1616
sha3 = { workspace = true }
1717
hex = { workspace = true }
18-
ic-oss = { path = "../ic_oss", version = "0.7" }
19-
ic-oss-types = { path = "../ic_oss_types", version = "0.7" }
18+
ic-oss = { path = "../ic_oss", version = "0.8" }
19+
ic-oss-types = { path = "../ic_oss_types", version = "0.8" }
2020
ic-agent = "0.36"
2121
anyhow = "1"
2222
clap = { version = "=4.5", features = ["derive"] }

src/ic_oss_cluster/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,4 +25,4 @@ hex = { workspace = true }
2525
serde = { workspace = true }
2626
serde_bytes = { workspace = true }
2727
getrandom = { workspace = true }
28-
ic-oss-types = { path = "../ic_oss_types", version = "0.7" }
28+
ic-oss-types = { path = "../ic_oss_types", version = "0.8" }

src/ic_oss_cluster/src/store.rs

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -24,23 +24,27 @@ type Memory = VirtualMemory<DefaultMemoryImpl>;
2424

2525
#[derive(Clone, Default, Deserialize, Serialize)]
2626
pub struct State {
27-
#[serde(default)]
27+
#[serde(default, rename = "n", alias = "name")]
2828
pub name: String,
29+
#[serde(rename = "k", alias = "ecdsa_key_name")]
2930
pub ecdsa_key_name: String,
31+
#[serde(rename = "t", alias = "ecdsa_token_public_key")]
3032
pub ecdsa_token_public_key: String,
33+
#[serde(rename = "e", alias = "token_expiration")]
3134
pub token_expiration: u64, // in seconds
35+
#[serde(rename = "m", alias = "managers")]
3236
pub managers: BTreeSet<Principal>,
33-
#[serde(default)]
37+
#[serde(default, rename = "lv", alias = "bucket_latest_version")]
3438
pub bucket_latest_version: ByteArray<32>,
35-
#[serde(default)]
39+
#[serde(default, rename = "p", alias = "bucket_upgrade_path")]
3640
pub bucket_upgrade_path: HashMap<ByteArray<32>, ByteArray<32>>,
37-
#[serde(default)]
41+
#[serde(default, rename = "dl", alias = "bucket_deployed_list")]
3842
pub bucket_deployed_list: BTreeMap<Principal, (u64, ByteArray<32>)>,
39-
#[serde(default)]
43+
#[serde(default, rename = "up", alias = "bucket_upgrade_process")]
4044
pub bucket_upgrade_process: Option<ByteBuf>,
41-
#[serde(default)]
45+
#[serde(default, rename = "tt", alias = "bucket_topup_threshold")]
4246
pub bucket_topup_threshold: u128,
43-
#[serde(default)]
47+
#[serde(default, rename = "ta", alias = "bucket_topup_amount")]
4448
pub bucket_topup_amount: u128,
4549
}
4650

@@ -98,9 +102,13 @@ impl Storable for PoliciesTable {
98102

99103
#[derive(Clone, Deserialize, Serialize)]
100104
pub struct Wasm {
105+
#[serde(rename = "a", alias = "created_at")]
101106
pub created_at: u64, // in milliseconds
107+
#[serde(rename = "b", alias = "created_by")]
102108
pub created_by: Principal,
109+
#[serde(rename = "d", alias = "description")]
103110
pub description: String,
111+
#[serde(rename = "w", alias = "wasm")]
104112
pub wasm: ByteBuf,
105113
}
106114

@@ -120,11 +128,17 @@ impl Storable for Wasm {
120128

121129
#[derive(Clone, Deserialize, Serialize)]
122130
pub struct DeployLog {
131+
#[serde(rename = "d", alias = "deploy_at")]
123132
pub deploy_at: u64, // in milliseconds
133+
#[serde(rename = "c", alias = "canister")]
124134
pub canister: Principal,
135+
#[serde(rename = "p", alias = "prev_hash")]
125136
pub prev_hash: ByteArray<32>,
137+
#[serde(rename = "w", alias = "wasm_hash")]
126138
pub wasm_hash: ByteArray<32>,
139+
#[serde(rename = "a", alias = "args")]
127140
pub args: ByteBuf,
141+
#[serde(rename = "e", alias = "error")]
128142
pub error: Option<String>,
129143
}
130144

src/ic_oss_types/src/bytes.rs

Lines changed: 0 additions & 105 deletions
This file was deleted.

src/ic_oss_types/src/lib.rs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,6 @@ pub mod file;
1414
pub mod folder;
1515
pub mod permission;
1616

17-
mod bytes;
18-
pub use bytes::*;
19-
2017
// should update to ICRC3Map
2118
pub type MapValue =
2219
BTreeMap<String, icrc_ledger_types::icrc::generic_metadata_value::MetadataValue>;

0 commit comments

Comments
 (0)