From 6e37e2d4a9271f1f6498e956a326dfdfe1744c36 Mon Sep 17 00:00:00 2001 From: amigin Date: Sun, 7 Apr 2024 16:58:40 +0300 Subject: [PATCH] Made some optimizations --- .../http_connection/into_http_payload.rs | 34 +++++++++++++++---- .../tcp_connection/tcp_payload_to_send.rs | 7 ++-- .../read/get_highest_row_and_below.rs | 4 +-- src/db_operations/read/multipart.rs | 2 +- src/db_operations/read/rows/get_all.rs | 4 +-- .../read/rows/get_all_by_partition_key.rs | 4 +-- .../read/rows/get_all_by_row_key.rs | 4 +-- .../get_single_partition_multiple_rows.rs | 4 +-- .../states/delete_rows_event_sync_data.rs | 2 +- .../sync/upload_partition.rs | 2 +- src/zip/db_zip_builder.rs | 2 +- 11 files changed, 39 insertions(+), 30 deletions(-) diff --git a/src/data_readers/http_connection/into_http_payload.rs b/src/data_readers/http_connection/into_http_payload.rs index 8f7f116..583772a 100644 --- a/src/data_readers/http_connection/into_http_payload.rs +++ b/src/data_readers/http_connection/into_http_payload.rs @@ -33,12 +33,17 @@ fn write_init_table_result(table_name: &str, content: JsonArrayWriter) -> Vec Vec< let mut header_json = JsonObjectWriter::new(); header_json.write("tableName", sync_data.table_data.table_name.as_str()); - let header = format!("initPartitions:{}", header_json.build()); + let header = unsafe { + format!( + "initPartitions:{}", + std::str::from_utf8_unchecked(header_json.build().as_slice()) + ) + }; write_pascal_string(header.as_str(), &mut result); let content = sync_data.as_json().build(); - write_byte_array(content.as_bytes(), &mut result); + write_byte_array(content.as_slice(), &mut result); result } @@ -62,12 +72,17 @@ pub fn compile_update_rows_result(sync_data: &UpdateRowsSyncData) -> Vec { let mut header_json = JsonObjectWriter::new(); header_json.write("tableName", sync_data.table_data.table_name.as_str()); - let header = format!("updateRows:{}", header_json.build()); + let header = unsafe { + format!( + "updateRows:{}", + std::str::from_utf8_unchecked(header_json.build().as_slice()) + ) + }; write_pascal_string(header.as_str(), &mut result); let content = sync_data.rows_by_partition.as_json_array().build(); - write_byte_array(content.as_bytes(), &mut result); + write_byte_array(content.as_slice(), &mut result); result } @@ -77,7 +92,12 @@ pub fn compile_delete_rows_result(sync_data: &DeleteRowsEventSyncData) -> Vec Vec Vec Vec Vec { let tcp_contract = MyNoSqlTcpContract::UpdateRows { table_name: data.table_data.table_name.to_string(), - data: data.rows_by_partition.as_json_array().build().into_bytes(), + data: data.rows_by_partition.as_json_array().build(), }; if compress { diff --git a/src/db_operations/read/get_highest_row_and_below.rs b/src/db_operations/read/get_highest_row_and_below.rs index 9288c0f..973cdb0 100644 --- a/src/db_operations/read/get_highest_row_and_below.rs +++ b/src/db_operations/read/get_highest_row_and_below.rs @@ -46,9 +46,7 @@ pub async fn get_highest_row_and_below( count += 1; } - return Ok(ReadOperationResult::RowsArray( - json_array_writer.build().into_bytes(), - )); + return Ok(ReadOperationResult::RowsArray(json_array_writer.build())); /* let mut json_array_writer = JsonArrayWriter::new(); diff --git a/src/db_operations/read/multipart.rs b/src/db_operations/read/multipart.rs index 0244c66..44c3a49 100644 --- a/src/db_operations/read/multipart.rs +++ b/src/db_operations/read/multipart.rs @@ -25,5 +25,5 @@ pub async fn get_next( ) -> Option { let db_rows = app.multipart_list.get(multipart_id, amount).await?; - ReadOperationResult::RowsArray(db_rows.as_json_array().build().into_bytes()).into() + ReadOperationResult::RowsArray(db_rows.as_json_array().build()).into() } diff --git a/src/db_operations/read/rows/get_all.rs b/src/db_operations/read/rows/get_all.rs index d0811cd..bbcfaf5 100644 --- a/src/db_operations/read/rows/get_all.rs +++ b/src/db_operations/read/rows/get_all.rs @@ -29,9 +29,7 @@ pub async fn get_all( json_array_writer.write(db_row.as_ref()); } - return Ok(ReadOperationResult::RowsArray( - json_array_writer.build().into_bytes(), - )); + return Ok(ReadOperationResult::RowsArray(json_array_writer.build())); } /* diff --git a/src/db_operations/read/rows/get_all_by_partition_key.rs b/src/db_operations/read/rows/get_all_by_partition_key.rs index 34173f4..7566ea9 100644 --- a/src/db_operations/read/rows/get_all_by_partition_key.rs +++ b/src/db_operations/read/rows/get_all_by_partition_key.rs @@ -40,7 +40,5 @@ pub async fn get_all_by_partition_key( }, ); - return Ok(ReadOperationResult::RowsArray( - json_array_writer.build().into_bytes(), - )); + return Ok(ReadOperationResult::RowsArray(json_array_writer.build())); } diff --git a/src/db_operations/read/rows/get_all_by_row_key.rs b/src/db_operations/read/rows/get_all_by_row_key.rs index 1e22733..ecd65b6 100644 --- a/src/db_operations/read/rows/get_all_by_row_key.rs +++ b/src/db_operations/read/rows/get_all_by_row_key.rs @@ -30,7 +30,5 @@ pub async fn get_all_by_row_key( json_array_writer.write(db_row.as_ref()); } - return Ok(ReadOperationResult::RowsArray( - json_array_writer.build().into_bytes(), - )); + return Ok(ReadOperationResult::RowsArray(json_array_writer.build())); } diff --git a/src/db_operations/read/rows/get_single_partition_multiple_rows.rs b/src/db_operations/read/rows/get_single_partition_multiple_rows.rs index 9299d48..79f0715 100644 --- a/src/db_operations/read/rows/get_single_partition_multiple_rows.rs +++ b/src/db_operations/read/rows/get_single_partition_multiple_rows.rs @@ -39,9 +39,7 @@ pub async fn get_single_partition_multiple_rows( json_array_writer.write(db_row.as_ref()); } } - return Ok(ReadOperationResult::RowsArray( - json_array_writer.build().into_bytes(), - )); + return Ok(ReadOperationResult::RowsArray(json_array_writer.build())); } /* diff --git a/src/db_sync/states/delete_rows_event_sync_data.rs b/src/db_sync/states/delete_rows_event_sync_data.rs index cb09189..e1d75b7 100644 --- a/src/db_sync/states/delete_rows_event_sync_data.rs +++ b/src/db_sync/states/delete_rows_event_sync_data.rs @@ -139,6 +139,6 @@ impl DeleteRowsEventSyncData { } } - json_object_writer.build().into_bytes() + json_object_writer.build() } } diff --git a/src/persist_operations/sync/upload_partition.rs b/src/persist_operations/sync/upload_partition.rs index 7b43f83..396353a 100644 --- a/src/persist_operations/sync/upload_partition.rs +++ b/src/persist_operations/sync/upload_partition.rs @@ -9,7 +9,7 @@ pub async fn upload_partition(app: &AppContext, table_name: &str, snapshot: DbPa .save_table_file( table_name, &TableFile::DbPartition(snapshot.partition_key.clone()), - content.build().into_bytes(), + content.build(), ) .await; diff --git a/src/zip/db_zip_builder.rs b/src/zip/db_zip_builder.rs index f116ade..1a14bf9 100644 --- a/src/zip/db_zip_builder.rs +++ b/src/zip/db_zip_builder.rs @@ -44,7 +44,7 @@ impl DbZipBuilder { let json = itm.db_rows_snapshot.as_json_array(); - let payload = json.build().into_bytes(); + let payload = json.build(); write_to_zip_file(&mut self.zip_writer, &payload)?; }