about summary refs log tree commit diff
path: root/src/database
diff options
context:
space:
mode:
authorVika <vika@fireburn.ru>2024-08-26 14:08:07 +0300
committerVika <vika@fireburn.ru>2024-08-26 14:36:57 +0300
commitc79e950ca22c7a957c11e510700664327b042115 (patch)
tree1387e5931dd08cea0d21b2770964e169d7043905 /src/database
parent1a4a9b85b9bf9ae8650a2cd68416476c7d1770b3 (diff)
downloadkittybox-c79e950ca22c7a957c11e510700664327b042115.tar.zst
Appease most clippy warnings
The warnings only remain in places where I need them to remain,
because I either need a reminder to implement something, or I need to
refactor and simplify the code in question.
Diffstat (limited to 'src/database')
-rw-r--r--src/database/mod.rs9
-rw-r--r--src/database/postgres/mod.rs67
2 files changed, 6 insertions, 70 deletions
diff --git a/src/database/mod.rs b/src/database/mod.rs
index 7b50196..3b13cb3 100644
--- a/src/database/mod.rs
+++ b/src/database/mod.rs
@@ -55,7 +55,9 @@ pub mod settings {
     /// implementations, as it wouldn't make sense to add new settings
     /// that aren't used by Kittybox itself.
     pub trait Setting<'de>: private::Sealed + std::fmt::Debug + Default + Clone + serde::Serialize + serde::de::DeserializeOwned + /*From<Settings> +*/ Send + Sync {
+        /// The data that the setting carries.
         type Data: std::fmt::Debug + Send + Sync;
+        /// The string ID for the setting, usable as an identifier in the database.
         const ID: &'static str;
 
         /// Unwrap the setting type, returning owned data contained within.
@@ -89,11 +91,6 @@ pub mod settings {
             Self(data)
         }
     }
-    impl SiteName {
-        fn from_str(data: &str) -> Self {
-            Self(data.to_owned())
-        }
-    }
 
     /// Participation status in the IndieWeb Webring: https://πŸ•ΈπŸ’.ws/dashboard
     #[derive(Debug, Default, serde::Deserialize, serde::Serialize, Clone, Copy, PartialEq, Eq)]
@@ -600,7 +597,7 @@ mod tests {
             .await
             .unwrap();
 
-        for (i, post) in posts.iter().rev().enumerate() {
+        for post in posts.iter().rev() {
             backend
                 .put_post(post, &"https://fireburn.ru/".parse().unwrap())
                 .await
diff --git a/src/database/postgres/mod.rs b/src/database/postgres/mod.rs
index 1780672..b2d4339 100644
--- a/src/database/postgres/mod.rs
+++ b/src/database/postgres/mod.rs
@@ -247,11 +247,6 @@ WHERE
 
     #[tracing::instrument(skip(self))]
     async fn get_channels(&self, user: &url::Url) -> Result<Vec<MicropubChannel>> {
-        /*sqlx::query_as::<_, MicropubChannel>("SELECT name, uid FROM kittybox.channels WHERE owner = $1")
-            .bind(user)
-            .fetch_all(&self.db)
-            .await
-            .map_err(|err| err.into())*/
         sqlx::query_as::<_, MicropubChannel>(r#"SELECT mf2 #>> '{properties,name,0}' as name, uid FROM kittybox.mf2_json WHERE '["h-feed"]'::jsonb @> mf2['type'] AND owner = $1"#)
             .bind(user.authority())
             .fetch_all(&self.db)
@@ -263,67 +258,11 @@ WHERE
     async fn read_feed_with_limit(
         &self,
         url: &'_ str,
-        after: Option<&str>,
-        limit: usize,
-        // BUG: this doesn't seem to be used?!
-        user: Option<&url::Url>,
+        _after: Option<&str>,
+        _limit: usize,
+        _user: Option<&url::Url>,
     ) -> Result<Option<serde_json::Value>> {
         unimplemented!("read_feed_with_limit is insecure and deprecated");
-        let mut feed = match sqlx::query_as::<_, (serde_json::Value,)>("
-SELECT jsonb_set(
-    mf2,
-    '{properties,author,0}',
-    (SELECT mf2 FROM kittybox.mf2_json
-     WHERE uid = mf2 #>> '{properties,author,0}')
-) FROM kittybox.mf2_json WHERE uid = $1 OR mf2['properties']['url'] ? $1
-")
-            .bind(url)
-            .fetch_optional(&self.db)
-            .await?
-            .map(|v| v.0)
-        {
-            Some(feed) => feed,
-            None => return Ok(None)
-        };
-
-        let posts: Vec<String> = {
-            let mut posts_iter = feed["children"]
-                .as_array()
-                .cloned()
-                .unwrap_or_default()
-                .into_iter()
-                .map(|s| s.as_str().unwrap().to_string());
-            if let Some(after) = after {
-                for s in posts_iter.by_ref() {
-                    if &s == after {
-                        break;
-                    }
-                }
-            };
-
-            posts_iter.take(limit).collect::<Vec<_>>()
-        };
-        feed["children"] = serde_json::Value::Array(
-            sqlx::query_as::<_, (serde_json::Value,)>("
-SELECT jsonb_set(
-    mf2,
-    '{properties,author,0}',
-    (SELECT mf2 FROM kittybox.mf2_json
-     WHERE uid = mf2 #>> '{properties,author,0}')
-) FROM kittybox.mf2_json
-WHERE uid = ANY($1)
-ORDER BY mf2 #>> '{properties,published,0}' DESC
-")
-                .bind(&posts[..])
-                .fetch_all(&self.db)
-                .await?
-                .into_iter()
-                .map(|v| v.0)
-                .collect::<Vec<_>>()
-        );
-
-        Ok(Some(feed))
-
     }
 
     #[tracing::instrument(skip(self))]