From c79e950ca22c7a957c11e510700664327b042115 Mon Sep 17 00:00:00 2001 From: Vika Date: Mon, 26 Aug 2024 14:08:07 +0300 Subject: 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. --- src/database/postgres/mod.rs | 67 ++------------------------------------------ 1 file changed, 3 insertions(+), 64 deletions(-) (limited to 'src/database/postgres') 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> { - /*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> { 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 = { - 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::>() - }; - 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::>() - ); - - Ok(Some(feed)) - } #[tracing::instrument(skip(self))] -- cgit 1.4.1