From 9c977908769034c9fd95b82c22da568a365728c4 Mon Sep 17 00:00:00 2001 From: Aumetra Weisman Date: Sun, 26 May 2024 19:38:09 +0200 Subject: [PATCH] use combined branch --- Cargo.lock | 2 +- Cargo.toml | 2 +- crates/kitsune-db/src/json.rs | 13 ++++++------- 3 files changed, 8 insertions(+), 9 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 09cf92159..d5d50e7b3 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -6368,7 +6368,7 @@ dependencies = [ [[package]] name = "sonic-rs" version = "0.3.6" -source = "git+https://github.com/cloudwego/sonic-rs.git?rev=8808ec64ce198a65b525cba07306aef499862777#8808ec64ce198a65b525cba07306aef499862777" +source = "git+https://github.com/cloudwego/sonic-rs.git?rev=d1f172d75e7c9386fde169673d2666e0cfd5d32c#d1f172d75e7c9386fde169673d2666e0cfd5d32c" dependencies = [ "arrayref", "bumpalo", diff --git a/Cargo.toml b/Cargo.toml index f39030ab2..302577984 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -213,7 +213,7 @@ scraper = { git = "https://github.com/causal-agent/scraper.git", rev = "d67111f5 tokio-postgres-rustls = { git = "https://github.com/jbg/tokio-postgres-rustls.git", rev = "b16c1bc0f5d4f91324174fd1bd839d743a70f86a" } # SIMD runtime detection -sonic-rs = { git = "https://github.com/cloudwego/sonic-rs.git", rev = "8808ec64ce198a65b525cba07306aef499862777" } +sonic-rs = { git = "https://github.com/cloudwego/sonic-rs.git", rev = "d1f172d75e7c9386fde169673d2666e0cfd5d32c" } # TCP nodelay for `axum::serve` axum = { git = "https://github.com/tokio-rs/axum.git", rev = "8d0c5c05eb75eb779591c8000705e785123868a0" } diff --git a/crates/kitsune-db/src/json.rs b/crates/kitsune-db/src/json.rs index 7d3fade4e..ec9990065 100644 --- a/crates/kitsune-db/src/json.rs +++ b/crates/kitsune-db/src/json.rs @@ -7,6 +7,7 @@ use diesel::{ AsExpression, FromSqlRow, }; use serde::{de::DeserializeOwned, Deserialize, Serialize}; +use sonic_rs::writer::BufferedWriter; use std::{ error::Error, fmt::{self, Debug}, @@ -48,6 +49,7 @@ impl FromSql for Json where T: DeserializeOwned, { + #[inline] fn from_sql(bytes: ::RawValue<'_>) -> deserialize::Result { let bytes = bytes.as_bytes(); if bytes[0] != 1 { @@ -61,14 +63,11 @@ impl ToSql for Json where T: Debug + Serialize, { + #[inline] fn to_sql<'b>(&'b self, out: &mut serialize::Output<'b, '_, Pg>) -> serialize::Result { out.write_all(&[1])?; - - // TODO: Intermediate buffering for now. Remove once sonic-rs gets the ability to skip this - // See: - let vec = sonic_rs::to_vec(self)?; - out.write_all(&vec)?; - - Ok(IsNull::No) + sonic_rs::to_writer(BufferedWriter::new(out), self) + .map(|()| IsNull::No) + .map_err(Into::into) } }