فهرست منبع

Amend queries to 1-based indices

Mark Rousskov 5 سال پیش
والد
کامیت
929798d7c8
2فایلهای تغییر یافته به همراه14 افزوده شده و 6 حذف شده
  1. 4 4
      src/db/notifications.rs
  2. 10 2
      src/zulip.rs

+ 4 - 4
src/db/notifications.rs

@@ -68,7 +68,7 @@ pub async fn move_indices(
                 "select notification_id, idx, user_id
         from notifications
         where user_id = $1
-        order by notifications.idx desc, notifications.time desc;",
+        order by idx desc, time desc;",
                 &[&user_id],
             )
             .await
@@ -101,9 +101,9 @@ pub async fn move_indices(
 
         for (idx, id) in notifications.into_iter().enumerate() {
             t.execute(
-                "update notifications SET notifications.idx = $2
-                 where notifications.notification_id = $1",
-                &[&id, &(idx as i64)],
+                "update notifications SET idx = $2
+                 where notification_id = $1",
+                &[&id, &(idx as i32)],
             )
             .await
             .context("update notification id")?;

+ 10 - 2
src/zulip.rs

@@ -132,8 +132,16 @@ async fn move_notification(
         Some(idx) => idx,
         None => anyhow::bail!("from idx not present"),
     };
-    let from = from.parse::<usize>().context("from index")?;
-    let to = to.parse::<usize>().context("to index")?;
+    let from = from
+        .parse::<usize>()
+        .context("from index")?
+        .checked_sub(1)
+        .ok_or_else(|| anyhow::anyhow!("1-based indexes"))?;
+    let to = to
+        .parse::<usize>()
+        .context("to index")?
+        .checked_sub(1)
+        .ok_or_else(|| anyhow::anyhow!("1-based indexes"))?;
     match move_indices(
         &mut Context::make_db_client(&ctx.github.raw()).await?,
         gh_id,