Compare commits

...

1 Commits

Author SHA1 Message Date
Conrad Irwin
e3350d3975 Remove bincode from workspace serialization
Using bincode makes it quite tricky to debug the workspaces table, as it
contains leading null bytes (which sqlite doesn't handle well).

JSON is much easier to use, and more space-efficient to boot.
2024-04-16 21:49:02 -06:00
5 changed files with 63 additions and 9 deletions

1
Cargo.lock generated
View File

@@ -12265,7 +12265,6 @@ dependencies = [
"any_vec",
"anyhow",
"async-recursion 1.0.5",
"bincode",
"call",
"client",
"clock",

View File

@@ -79,6 +79,7 @@ pub async fn open_db<M: Migrator + 'static>(
}
async fn open_main_db<M: Migrator>(db_path: &PathBuf) -> Option<ThreadSafeConnection<M>> {
dbg!(&db_path);
log::info!("Opening main db");
ThreadSafeConnection::<M>::builder(db_path.to_string_lossy().as_ref(), true)
.with_db_initialization_query(DB_INITIALIZE_QUERY)

View File

@@ -27,7 +27,6 @@ test-support = [
anyhow.workspace = true
any_vec.workspace = true
async-recursion.workspace = true
bincode = "1.2.1"
call.workspace = true
client.workspace = true
clock.workspace = true

View File

@@ -125,7 +125,7 @@ define_connection! {
//
// workspaces(
// workspace_id: usize, // Primary key for workspaces
// workspace_location: Bincode<Vec<PathBuf>>,
// workspace_location: Vec<PathBuf>,
// dock_visible: bool, // Deprecated
// dock_anchor: DockAnchor, // Deprecated
// dock_pane: Option<usize>, // Deprecated
@@ -289,7 +289,64 @@ define_connection! {
sql!(
ALTER TABLE workspaces ADD COLUMN centered_layout INTEGER; //bool
),
// remove bincode
sql!(
CREATE TABLE workspaces_2(
workspace_id INTEGER PRIMARY KEY,
workspace_location TEXT UNIQUE,
dock_visible INTEGER,
dock_anchor TEXT,
dock_pane INTEGER,
left_sidebar_open INTEGER,
timestamp TEXT DEFAULT CURRENT_TIMESTAMP NOT NULL,
window_state TEXT,
window_x REAL,
window_y REAL,
window_width REAL,
window_height REAL,
display BLOB,
left_dock_visible INTEGER,
left_dock_active_panel TEXT,
right_dock_visible INTEGER,
right_dock_active_panel TEXT,
bottom_dock_visible INTEGER,
bottom_dock_active_panel TEXT,
left_dock_zoom INTEGER,
right_dock_zoom INTEGER,
bottom_dock_zoom INTEGER,
fullscreen INTEGER,
centered_layout INTEGER
) STRICT;
INSERT INTO workspaces_2 SELECT
workspace_id,
json_array(cast(unhex(substr(hex(workspace_location), 33)) as text)) as workspace_location,
dock_visible,
dock_anchor,
dock_pane,
left_sidebar_open,
timestamp,
window_state,
window_x,
window_y,
window_width,
window_height,
display,
left_dock_visible,
left_dock_active_panel,
right_dock_visible,
right_dock_active_panel,
bottom_dock_visible,
bottom_dock_active_panel,
left_dock_zoom,
right_dock_zoom,
bottom_dock_zoom,
fullscreen,
centered_layout
FROM workspaces
WHERE substr(hex(workspace_location), 0, 17) == "0100000000000000";
DROP TABLE workspaces;
ALTER TABLE workspaces_2 RENAME TO workspaces;
),
];
}

View File

@@ -48,17 +48,15 @@ impl<P: AsRef<Path>, T: IntoIterator<Item = P>> From<T> for WorkspaceLocation {
impl StaticColumnCount for WorkspaceLocation {}
impl Bind for &WorkspaceLocation {
fn bind(&self, statement: &Statement, start_index: i32) -> Result<i32> {
bincode::serialize(&self.0)
.expect("Bincode serialization of paths should not fail")
.bind(statement, start_index)
statement.bind(&dbg!(serde_json::to_string(&self.0)?), start_index)
}
}
impl Column for WorkspaceLocation {
fn column(statement: &mut Statement, start_index: i32) -> Result<(Self, i32)> {
let blob = statement.column_blob(start_index)?;
let blob = statement.column_text(start_index)?;
Ok((
WorkspaceLocation(bincode::deserialize(blob).context("Bincode failed")?),
WorkspaceLocation(serde_json::from_str(blob).context("JSON failed")?),
start_index + 1,
))
}