aboutsummaryrefslogtreecommitdiffstats
path: root/rust/src
diff options
context:
space:
mode:
authorBryan Newbold <bnewbold@robocracy.org>2018-12-20 23:28:08 -0800
committerBryan Newbold <bnewbold@robocracy.org>2018-12-20 23:28:08 -0800
commit49b18c6c2e49144710ad75c7e5ed3c24146d0cdb (patch)
treec1b9a962bfe40779afae4897bab60e52cf3b5f0f /rust/src
parentb96964bd867c17619cfaf62da517852ac35cdb1c (diff)
downloadfatcat-49b18c6c2e49144710ad75c7e5ed3c24146d0cdb.tar.gz
fatcat-49b18c6c2e49144710ad75c7e5ed3c24146d0cdb.zip
fix order of entity update
Diffstat (limited to 'rust/src')
-rw-r--r--rust/src/api_entity_crud.rs37
1 files changed, 20 insertions, 17 deletions
diff --git a/rust/src/api_entity_crud.rs b/rust/src/api_entity_crud.rs
index 1b36f71d..3b12a446 100644
--- a/rust/src/api_entity_crud.rs
+++ b/rust/src/api_entity_crud.rs
@@ -433,23 +433,8 @@ macro_rules! generic_db_get_redirects {
macro_rules! generic_db_accept_edits_batch {
($entity_name_str:expr, $ident_table:ident, $edit_table:ident) => {
fn db_accept_edits(conn: &DbConn, editgroup_id: FatCatId) -> Result<u64> {
- let count = diesel::sql_query(format!(
- "
- UPDATE {entity}_ident
- SET
- is_live = true,
- rev_id = {entity}_edit.rev_id,
- redirect_id = {entity}_edit.redirect_id
- FROM {entity}_edit
- WHERE
- {entity}_ident.id = {entity}_edit.ident_id
- AND {entity}_edit.editgroup_id = $1",
- entity = $entity_name_str
- ))
- .bind::<diesel::sql_types::Uuid, _>(editgroup_id.to_uuid())
- .execute(conn)?;
- // NOTE: all the following can be skipped for accepts that are all inserts (which I
- // guess we only know for batch inserts with auto-accept?)
+ // NOTE: the checks and redirects can be skipped for accepts that are all inserts
+ // (which I guess we only know for batch inserts with auto-accept?)
// assert that we aren't redirecting to anything which is a redirect already
let forward_recursive_redirects: i64 = $edit_table::table
@@ -463,6 +448,7 @@ macro_rules! generic_db_accept_edits_batch {
.count()
.get_result(conn)?;
if forward_recursive_redirects != 0 {
+ // TODO: revert transaction?
return Err(ErrorKind::OtherBadRequest(
"one or more (forward) recurisve redirects".to_string(),
)
@@ -481,12 +467,29 @@ macro_rules! generic_db_accept_edits_batch {
.count()
.get_result(conn)?;
if backward_recursive_redirects != 0 {
+ // TODO: revert transaction?
return Err(ErrorKind::OtherBadRequest(
"one or more (backward) recurisve redirects".to_string(),
)
.into());
}
+ let count = diesel::sql_query(format!(
+ "
+ UPDATE {entity}_ident
+ SET
+ is_live = true,
+ rev_id = {entity}_edit.rev_id,
+ redirect_id = {entity}_edit.redirect_id
+ FROM {entity}_edit
+ WHERE
+ {entity}_ident.id = {entity}_edit.ident_id
+ AND {entity}_edit.editgroup_id = $1",
+ entity = $entity_name_str
+ ))
+ .bind::<diesel::sql_types::Uuid, _>(editgroup_id.to_uuid())
+ .execute(conn)?;
+
// update any/all redirects for updated entities
let _redir_count = diesel::sql_query(format!(
"