From ad58e900247ca9be2b29ea8f926c4120e1c9501a Mon Sep 17 00:00:00 2001 From: Bryan Newbold Date: Wed, 9 Jan 2019 13:06:11 -0800 Subject: start removing active editgroup code --- rust/src/database_models.rs | 1 - rust/src/database_schema.rs | 2 +- rust/src/editing.rs | 21 +++------------------ 3 files changed, 4 insertions(+), 20 deletions(-) (limited to 'rust/src') diff --git a/rust/src/database_models.rs b/rust/src/database_models.rs index 4575aeaf..0b6de130 100644 --- a/rust/src/database_models.rs +++ b/rust/src/database_models.rs @@ -584,7 +584,6 @@ pub struct EditorRow { pub registered: chrono::NaiveDateTime, pub auth_epoch: chrono::NaiveDateTime, pub wrangler_id: Option, - pub active_editgroup_id: Option, } impl EditorRow { diff --git a/rust/src/database_schema.rs b/rust/src/database_schema.rs index 0c553b40..ac5acec8 100644 --- a/rust/src/database_schema.rs +++ b/rust/src/database_schema.rs @@ -114,7 +114,6 @@ table! { registered -> Timestamptz, auth_epoch -> Timestamptz, wrangler_id -> Nullable, - active_editgroup_id -> Nullable, } } @@ -406,6 +405,7 @@ joinable!(container_edit -> editgroup (editgroup_id)); joinable!(container_ident -> container_rev (rev_id)); joinable!(creator_edit -> editgroup (editgroup_id)); joinable!(creator_ident -> creator_rev (rev_id)); +joinable!(editgroup -> editor (editor_id)); joinable!(file_edit -> editgroup (editgroup_id)); joinable!(file_ident -> file_rev (rev_id)); joinable!(file_rev_release -> file_rev (file_rev)); diff --git a/rust/src/editing.rs b/rust/src/editing.rs index b488e489..42dd013e 100644 --- a/rust/src/editing.rs +++ b/rust/src/editing.rs @@ -45,7 +45,7 @@ pub fn make_edit_context( .get_result(conn)?; FatCatId::from_uuid(&eg_row.id) } - (None, false) => FatCatId::from_uuid(&get_or_create_editgroup(conn, editor_id.to_uuid())?), + (None, false) => FatCatId::from_uuid(&create_editgroup(conn, editor_id.to_uuid())?), }; Ok(EditContext { editor_id, @@ -86,20 +86,11 @@ pub fn update_editor_username( } /// This function should always be run within a transaction -pub fn get_or_create_editgroup(conn: &DbConn, editor_id: Uuid) -> Result { - // check for current active - let ed_row: EditorRow = editor::table.find(editor_id).first(conn)?; - if let Some(current) = ed_row.active_editgroup_id { - return Ok(current); - } - +pub fn create_editgroup(conn: &DbConn, editor_id: Uuid) -> Result { // need to insert and update let eg_row: EditgroupRow = diesel::insert_into(editgroup::table) - .values((editgroup::editor_id.eq(ed_row.id),)) + .values((editgroup::editor_id.eq(editor_id),)) .get_result(conn)?; - diesel::update(editor::table.find(ed_row.id)) - .set(editor::active_editgroup_id.eq(eg_row.id)) - .execute(conn)?; Ok(eg_row.id) } @@ -130,11 +121,5 @@ pub fn accept_editgroup(conn: &DbConn, editgroup_id: FatCatId) -> Result = None; - diesel::update(editor::table) - .filter(editor::active_editgroup_id.eq(editgroup_id.to_uuid())) - .set(editor::active_editgroup_id.eq(no_active)) - .execute(conn)?; Ok(entry) } -- cgit v1.2.3