From 21e4355d5805ed83a54bf65b27111acb6889b3fa Mon Sep 17 00:00:00 2001 From: Jai A Date: Fri, 29 Mar 2024 21:19:56 -0700 Subject: [PATCH] Fix clippy errors --- ...876bf3d3225ca7b4994440a67cbd6a7b610f6.json | 8 -- ...743ee22f0d4665ced3aa66122a4f6623b4769.json | 102 ---------------- src/auth/checks.rs | 14 +-- src/database/models/categories.rs | 20 ++-- src/database/models/image_item.rs | 10 +- src/database/models/loader_fields.rs | 28 +++-- src/database/models/notification_item.rs | 112 +++++++++--------- src/database/models/pat_item.rs | 4 +- src/database/models/payout_item.rs | 6 +- src/database/models/project_item.rs | 14 +-- src/database/models/report_item.rs | 6 +- src/database/models/session_item.rs | 4 +- src/database/models/team_item.rs | 44 +++---- src/database/models/thread_item.rs | 12 +- src/database/models/user_item.rs | 20 ++-- src/database/redis.rs | 2 +- src/queue/session.rs | 7 +- src/routes/internal/moderation.rs | 4 +- src/routes/v3/organizations.rs | 8 +- src/routes/v3/projects.rs | 8 +- src/routes/v3/reports.rs | 14 +-- src/routes/v3/threads.rs | 66 +++++------ src/routes/v3/users.rs | 7 +- src/routes/v3/version_creation.rs | 4 +- src/search/indexing/local_import.rs | 8 +- src/util/extract.rs | 7 +- src/validate/fabric.rs | 7 +- src/validate/forge.rs | 17 +-- src/validate/quilt.rs | 7 +- src/validate/resourcepack.rs | 17 +-- 30 files changed, 211 insertions(+), 376 deletions(-) delete mode 100644 .sqlx/query-ae95eabd762a497932e5e66d37e743ee22f0d4665ced3aa66122a4f6623b4769.json diff --git a/.sqlx/query-32f4aa1ab67fbdcd7187fbae475876bf3d3225ca7b4994440a67cbd6a7b610f6.json b/.sqlx/query-32f4aa1ab67fbdcd7187fbae475876bf3d3225ca7b4994440a67cbd6a7b610f6.json index 4dcf6bfd..5fc3bd90 100644 --- a/.sqlx/query-32f4aa1ab67fbdcd7187fbae475876bf3d3225ca7b4994440a67cbd6a7b610f6.json +++ b/.sqlx/query-32f4aa1ab67fbdcd7187fbae475876bf3d3225ca7b4994440a67cbd6a7b610f6.json @@ -1,10 +1,6 @@ { "db_name": "PostgreSQL", -<<<<<<<< HEAD:.sqlx/query-ae95eabd762a497932e5e66d37e743ee22f0d4665ced3aa66122a4f6623b4769.json - "query": "\n SELECT v.id id, v.mod_id mod_id, v.author_id author_id, v.name version_name, v.version_number version_number,\n v.changelog changelog, v.date_published date_published, v.downloads downloads,\n v.version_type version_type, v.featured featured, v.status status, v.requested_status requested_status, v.ordering ordering\n FROM versions v\n WHERE v.id = ANY($1)\n ORDER BY v.ordering ASC NULLS LAST, v.date_published ASC;\n ", -======== "query": "\n SELECT v.id id, v.mod_id mod_id, v.author_id author_id, v.name version_name, v.version_number version_number,\n v.changelog changelog, v.date_published date_published, v.downloads downloads,\n v.version_type version_type, v.featured featured, v.status status, v.requested_status requested_status, v.ordering ordering\n FROM versions v\n WHERE v.id = ANY($1);\n ", ->>>>>>>> master:.sqlx/query-32f4aa1ab67fbdcd7187fbae475876bf3d3225ca7b4994440a67cbd6a7b610f6.json "describe": { "columns": [ { @@ -94,9 +90,5 @@ true ] }, -<<<<<<<< HEAD:.sqlx/query-ae95eabd762a497932e5e66d37e743ee22f0d4665ced3aa66122a4f6623b4769.json - "hash": "ae95eabd762a497932e5e66d37e743ee22f0d4665ced3aa66122a4f6623b4769" -======== "hash": "32f4aa1ab67fbdcd7187fbae475876bf3d3225ca7b4994440a67cbd6a7b610f6" ->>>>>>>> master:.sqlx/query-32f4aa1ab67fbdcd7187fbae475876bf3d3225ca7b4994440a67cbd6a7b610f6.json } diff --git a/.sqlx/query-ae95eabd762a497932e5e66d37e743ee22f0d4665ced3aa66122a4f6623b4769.json b/.sqlx/query-ae95eabd762a497932e5e66d37e743ee22f0d4665ced3aa66122a4f6623b4769.json deleted file mode 100644 index 4dcf6bfd..00000000 --- a/.sqlx/query-ae95eabd762a497932e5e66d37e743ee22f0d4665ced3aa66122a4f6623b4769.json +++ /dev/null @@ -1,102 +0,0 @@ -{ - "db_name": "PostgreSQL", -<<<<<<<< HEAD:.sqlx/query-ae95eabd762a497932e5e66d37e743ee22f0d4665ced3aa66122a4f6623b4769.json - "query": "\n SELECT v.id id, v.mod_id mod_id, v.author_id author_id, v.name version_name, v.version_number version_number,\n v.changelog changelog, v.date_published date_published, v.downloads downloads,\n v.version_type version_type, v.featured featured, v.status status, v.requested_status requested_status, v.ordering ordering\n FROM versions v\n WHERE v.id = ANY($1)\n ORDER BY v.ordering ASC NULLS LAST, v.date_published ASC;\n ", -======== - "query": "\n SELECT v.id id, v.mod_id mod_id, v.author_id author_id, v.name version_name, v.version_number version_number,\n v.changelog changelog, v.date_published date_published, v.downloads downloads,\n v.version_type version_type, v.featured featured, v.status status, v.requested_status requested_status, v.ordering ordering\n FROM versions v\n WHERE v.id = ANY($1);\n ", ->>>>>>>> master:.sqlx/query-32f4aa1ab67fbdcd7187fbae475876bf3d3225ca7b4994440a67cbd6a7b610f6.json - "describe": { - "columns": [ - { - "ordinal": 0, - "name": "id", - "type_info": "Int8" - }, - { - "ordinal": 1, - "name": "mod_id", - "type_info": "Int8" - }, - { - "ordinal": 2, - "name": "author_id", - "type_info": "Int8" - }, - { - "ordinal": 3, - "name": "version_name", - "type_info": "Varchar" - }, - { - "ordinal": 4, - "name": "version_number", - "type_info": "Varchar" - }, - { - "ordinal": 5, - "name": "changelog", - "type_info": "Varchar" - }, - { - "ordinal": 6, - "name": "date_published", - "type_info": "Timestamptz" - }, - { - "ordinal": 7, - "name": "downloads", - "type_info": "Int4" - }, - { - "ordinal": 8, - "name": "version_type", - "type_info": "Varchar" - }, - { - "ordinal": 9, - "name": "featured", - "type_info": "Bool" - }, - { - "ordinal": 10, - "name": "status", - "type_info": "Varchar" - }, - { - "ordinal": 11, - "name": "requested_status", - "type_info": "Varchar" - }, - { - "ordinal": 12, - "name": "ordering", - "type_info": "Int4" - } - ], - "parameters": { - "Left": [ - "Int8Array" - ] - }, - "nullable": [ - false, - false, - false, - false, - false, - false, - false, - false, - false, - false, - false, - true, - true - ] - }, -<<<<<<<< HEAD:.sqlx/query-ae95eabd762a497932e5e66d37e743ee22f0d4665ced3aa66122a4f6623b4769.json - "hash": "ae95eabd762a497932e5e66d37e743ee22f0d4665ced3aa66122a4f6623b4769" -======== - "hash": "32f4aa1ab67fbdcd7187fbae475876bf3d3225ca7b4994440a67cbd6a7b610f6" ->>>>>>>> master:.sqlx/query-32f4aa1ab67fbdcd7187fbae475876bf3d3225ca7b4994440a67cbd6a7b610f6.json -} diff --git a/src/auth/checks.rs b/src/auth/checks.rs index fe3a7878..699d7cb3 100644 --- a/src/auth/checks.rs +++ b/src/auth/checks.rs @@ -141,14 +141,12 @@ pub async fn filter_enlisted_projects_ids( .collect::>(), user_id as database::models::ids::UserId, ) - .fetch_many(pool) - .try_for_each(|e| { - if let Some(row) = e.right() { - for x in projects.iter() { - let bool = Some(x.id.0) == row.id && Some(x.team_id.0) == row.team_id; - if bool { - return_projects.push(x.id); - } + .fetch(pool) + .try_for_each(|row| { + for x in projects.iter() { + let bool = Some(x.id.0) == row.id && Some(x.team_id.0) == row.team_id; + if bool { + return_projects.push(x.id); } } diff --git a/src/database/models/categories.rs b/src/database/models/categories.rs index 4e04dba5..96f5f2a4 100644 --- a/src/database/models/categories.rs +++ b/src/database/models/categories.rs @@ -108,9 +108,9 @@ impl Category { ORDER BY c.ordering, c.category " ) - .fetch_many(exec) - .try_filter_map(|e| async { - Ok(e.right().map(|c| Category { + .fetch(exec) + .try_filter_map(|c| async { + Ok(Some(Category { id: CategoryId(c.id), category: c.category, project_type: c.project_type, @@ -166,9 +166,9 @@ impl LinkPlatform { SELECT id, name, donation FROM link_platforms " ) - .fetch_many(exec) - .try_filter_map(|e| async { - Ok(e.right().map(|c| LinkPlatform { + .fetch(exec) + .try_filter_map(|c| async { + Ok(Some(LinkPlatform { id: LinkPlatformId(c.id), name: c.name, donation: c.donation, @@ -222,8 +222,8 @@ impl ReportType { SELECT name FROM report_types " ) - .fetch_many(exec) - .try_filter_map(|e| async { Ok(e.right().map(|c| c.name)) }) + .fetch(exec) + .try_filter_map(|e| async { Ok(Some(e.name)) }) .try_collect::>() .await?; @@ -272,8 +272,8 @@ impl ProjectType { SELECT name FROM project_types " ) - .fetch_many(exec) - .try_filter_map(|e| async { Ok(e.right().map(|c| c.name)) }) + .fetch(exec) + .try_filter_map(|c| async { Ok(Some(c.name)) }) .try_collect::>() .await?; diff --git a/src/database/models/image_item.rs b/src/database/models/image_item.rs index 28297c15..4ae4ead3 100644 --- a/src/database/models/image_item.rs +++ b/src/database/models/image_item.rs @@ -135,11 +135,11 @@ impl Image { report_id.map(|x| x.0), ) - .fetch_many(&mut **transaction) - .try_filter_map(|e| async { - Ok(e.right().map(|row| { - let id = ImageId(row.id); + .fetch(&mut **transaction) + .try_filter_map(|row| async { + let id = ImageId(row.id); + Ok(Some( Image { id, url: row.url, @@ -152,7 +152,7 @@ impl Image { thread_message_id: row.thread_message_id.map(ThreadMessageId), report_id: row.report_id.map(ReportId), } - })) + )) }) .try_collect::>() .await diff --git a/src/database/models/loader_fields.rs b/src/database/models/loader_fields.rs index e31b07ee..da5b8dbf 100644 --- a/src/database/models/loader_fields.rs +++ b/src/database/models/loader_fields.rs @@ -60,9 +60,9 @@ impl Game { SELECT id, slug, name, icon_url, banner_url FROM games ", ) - .fetch_many(exec) - .try_filter_map(|e| async { - Ok(e.right().map(|x| Game { + .fetch(exec) + .try_filter_map(|x| async { + Ok(Some(Game { id: GameId(x.id), slug: x.slug, name: x.name, @@ -151,9 +151,9 @@ impl Loader { GROUP BY l.id; ", ) - .fetch_many(exec) - .try_filter_map(|e| async { - Ok(e.right().map(|x| Loader { + .fetch(exec) + .try_filter_map(|x| async { + Ok(Some(Loader { id: LoaderId(x.id), loader: x.loader, icon: x.icon, @@ -451,18 +451,20 @@ impl LoaderField { FROM loader_fields lf ", ) - .fetch_many(exec) - .try_filter_map(|e| async { - Ok(e.right().and_then(|r| { - Some(LoaderField { + .fetch(exec) + .try_filter_map(|r| async { + if let Some(field_type) = LoaderFieldType::build(&r.field_type, r.enum_type) { + Ok(Some(LoaderField { id: LoaderFieldId(r.id), - field_type: LoaderFieldType::build(&r.field_type, r.enum_type)?, + field_type, field: r.field, optional: r.optional, min_val: r.min_val, max_val: r.max_val, - }) - })) + })) + } else { + Ok(None) + } }) .try_collect::>() .await?; diff --git a/src/database/models/notification_item.rs b/src/database/models/notification_item.rs index 49d2fe1f..91f119e3 100644 --- a/src/database/models/notification_item.rs +++ b/src/database/models/notification_item.rs @@ -110,34 +110,32 @@ impl Notification { ", ¬ification_ids_parsed ) - .fetch_many(exec) - .try_filter_map(|e| async { - Ok(e.right().map(|row| { - let id = NotificationId(row.id); - - Notification { - id, - user_id: UserId(row.user_id), - read: row.read, - created: row.created, - body: row.body.clone().and_then(|x| serde_json::from_value(x).ok()).unwrap_or_else(|| { - if let Some(name) = row.name { - NotificationBody::LegacyMarkdown { - notification_type: row.notification_type, - name, - text: row.text.unwrap_or_default(), - link: row.link.unwrap_or_default(), - actions: serde_json::from_value( - row.actions.unwrap_or_default(), - ) - .ok() - .unwrap_or_default(), - } - } else { - NotificationBody::Unknown + .fetch(exec) + .try_filter_map(|row| async { + let id = NotificationId(row.id); + + Ok(Some(Notification { + id, + user_id: UserId(row.user_id), + read: row.read, + created: row.created, + body: row.body.clone().and_then(|x| serde_json::from_value(x).ok()).unwrap_or_else(|| { + if let Some(name) = row.name { + NotificationBody::LegacyMarkdown { + notification_type: row.notification_type, + name, + text: row.text.unwrap_or_default(), + link: row.link.unwrap_or_default(), + actions: serde_json::from_value( + row.actions.unwrap_or_default(), + ) + .ok() + .unwrap_or_default(), } - }), - } + } else { + NotificationBody::Unknown + } + }), })) }) .try_collect::>() @@ -173,34 +171,32 @@ impl Notification { ", user_id as UserId ) - .fetch_many(exec) - .try_filter_map(|e| async { - Ok(e.right().map(|row| { - let id = NotificationId(row.id); - - Notification { - id, - user_id: UserId(row.user_id), - read: row.read, - created: row.created, - body: row.body.clone().and_then(|x| serde_json::from_value(x).ok()).unwrap_or_else(|| { - if let Some(name) = row.name { - NotificationBody::LegacyMarkdown { - notification_type: row.notification_type, - name, - text: row.text.unwrap_or_default(), - link: row.link.unwrap_or_default(), - actions: serde_json::from_value( - row.actions.unwrap_or_default(), - ) - .ok() - .unwrap_or_default(), - } - } else { - NotificationBody::Unknown + .fetch(exec) + .try_filter_map(|row| async { + let id = NotificationId(row.id); + + Ok(Some(Notification { + id, + user_id: UserId(row.user_id), + read: row.read, + created: row.created, + body: row.body.clone().and_then(|x| serde_json::from_value(x).ok()).unwrap_or_else(|| { + if let Some(name) = row.name { + NotificationBody::LegacyMarkdown { + notification_type: row.notification_type, + name, + text: row.text.unwrap_or_default(), + link: row.link.unwrap_or_default(), + actions: serde_json::from_value( + row.actions.unwrap_or_default(), + ) + .ok() + .unwrap_or_default(), } - }), - } + } else { + NotificationBody::Unknown + } + }), })) }) .try_collect::>() @@ -242,8 +238,8 @@ impl Notification { ", ¬ification_ids_parsed ) - .fetch_many(&mut **transaction) - .try_filter_map(|e| async { Ok(e.right().map(|x| UserId(x.user_id))) }) + .fetch(&mut **transaction) + .try_filter_map(|x| async move { Ok(Some(UserId(x.user_id))) }) .try_collect::>() .await?; @@ -285,8 +281,8 @@ impl Notification { ", ¬ification_ids_parsed ) - .fetch_many(&mut **transaction) - .try_filter_map(|e| async { Ok(e.right().map(|x| UserId(x.user_id))) }) + .fetch(&mut **transaction) + .try_filter_map(|x| async move { Ok(Some(UserId(x.user_id))) }) .try_collect::>() .await?; diff --git a/src/database/models/pat_item.rs b/src/database/models/pat_item.rs index 73e1c9fe..754c581b 100644 --- a/src/database/models/pat_item.rs +++ b/src/database/models/pat_item.rs @@ -167,8 +167,8 @@ impl PersonalAccessToken { ", user_id.0, ) - .fetch_many(exec) - .try_filter_map(|e| async { Ok(e.right().map(|x| PatId(x.id))) }) + .fetch(exec) + .try_filter_map(|x| async move { Ok(Some(PatId(x.id))) }) .try_collect::>() .await?; diff --git a/src/database/models/payout_item.rs b/src/database/models/payout_item.rs index c2d03f48..dd94d9db 100644 --- a/src/database/models/payout_item.rs +++ b/src/database/models/payout_item.rs @@ -74,9 +74,9 @@ impl Payout { ", &payout_ids.into_iter().map(|x| x.0).collect::>() ) - .fetch_many(exec) - .try_filter_map(|e| async { - Ok(e.right().map(|r| Payout { + .fetch(exec) + .try_filter_map(|r| async { + Ok(Some(Payout { id: PayoutId(r.id), user_id: UserId(r.user_id), created: r.created, diff --git a/src/database/models/project_item.rs b/src/database/models/project_item.rs index d462ca5d..25c7b9f6 100644 --- a/src/database/models/project_item.rs +++ b/src/database/models/project_item.rs @@ -359,8 +359,8 @@ impl Project { ", id as ProjectId, ) - .fetch_many(&mut **transaction) - .try_filter_map(|e| async { Ok(e.right().map(|x| ThreadId(x.id))) }) + .fetch(&mut **transaction) + .try_filter_map(|x| async move { Ok(Some(ThreadId(x.id))) }) .try_collect::>() .await?; @@ -444,8 +444,8 @@ impl Project { ", project.inner.team_id as TeamId, ) - .fetch_many(&mut **transaction) - .try_filter_map(|e| async { Ok(e.right().map(|x| UserId(x.user_id))) }) + .fetch(&mut **transaction) + .try_filter_map(|x| async move { Ok(Some(UserId(x.user_id))) }) .try_collect::>() .await?; @@ -893,9 +893,9 @@ impl Project { ", id as ProjectId ) - .fetch_many(exec) - .try_filter_map(|e| async { - Ok(e.right().map(|x| { + .fetch(exec) + .try_filter_map(|x| async move { + Ok(Some({ ( x.dependency_id.map(VersionId), if x.mod_id == Some(0) { diff --git a/src/database/models/report_item.rs b/src/database/models/report_item.rs index b6f478ea..d37071e8 100644 --- a/src/database/models/report_item.rs +++ b/src/database/models/report_item.rs @@ -86,9 +86,9 @@ impl Report { ", &report_ids_parsed ) - .fetch_many(exec) - .try_filter_map(|e| async { - Ok(e.right().map(|x| QueryReport { + .fetch(exec) + .try_filter_map(|x| async { + Ok(Some(QueryReport { id: ReportId(x.id), report_type: x.name, project_id: x.mod_id.map(ProjectId), diff --git a/src/database/models/session_item.rs b/src/database/models/session_item.rs index a85425d5..5ebd00d6 100644 --- a/src/database/models/session_item.rs +++ b/src/database/models/session_item.rs @@ -220,8 +220,8 @@ impl Session { ", user_id.0, ) - .fetch_many(exec) - .try_filter_map(|e| async { Ok(e.right().map(|x| SessionId(x.id))) }) + .fetch(exec) + .try_filter_map(|x| async move { Ok(Some(SessionId(x.id))) }) .try_collect::>() .await?; diff --git a/src/database/models/team_item.rs b/src/database/models/team_item.rs index e27432f2..eea83ab0 100644 --- a/src/database/models/team_item.rs +++ b/src/database/models/team_item.rs @@ -299,35 +299,27 @@ impl TeamMember { &team_ids_parsed, user_id as UserId ) - .fetch_many(executor) - .try_filter_map(|e| async { - if let Some(m) = e.right() { - Ok(Some(Ok(TeamMember { - id: TeamMemberId(m.id), - team_id: TeamId(m.team_id), - user_id, - role: m.role, - is_owner: m.is_owner, - permissions: ProjectPermissions::from_bits(m.permissions as u64) - .unwrap_or_default(), - organization_permissions: m - .organization_permissions - .map(|p| OrganizationPermissions::from_bits(p as u64).unwrap_or_default()), - accepted: m.accepted, - payouts_split: m.payouts_split, - ordering: m.ordering, - }))) - } else { - Ok(None) - } + .fetch(executor) + .try_filter_map(|m| async { + Ok(Some(TeamMember { + id: TeamMemberId(m.id), + team_id: TeamId(m.team_id), + user_id, + role: m.role, + is_owner: m.is_owner, + permissions: ProjectPermissions::from_bits(m.permissions as u64) + .unwrap_or_default(), + organization_permissions: m + .organization_permissions + .map(|p| OrganizationPermissions::from_bits(p as u64).unwrap_or_default()), + accepted: m.accepted, + payouts_split: m.payouts_split, + ordering: m.ordering, + })) }) - .try_collect::>>() + .try_collect::>() .await?; - let team_members = team_members - .into_iter() - .collect::, super::DatabaseError>>()?; - Ok(team_members) } diff --git a/src/database/models/thread_item.rs b/src/database/models/thread_item.rs index e085bb1b..029ff97b 100644 --- a/src/database/models/thread_item.rs +++ b/src/database/models/thread_item.rs @@ -144,9 +144,9 @@ impl Thread { ", &thread_ids_parsed ) - .fetch_many(exec) - .try_filter_map(|e| async { - Ok(e.right().map(|x| Thread { + .fetch(exec) + .try_filter_map(|x| async { + Ok(Some(Thread { id: ThreadId(x.id), project_id: x.mod_id.map(ProjectId), report_id: x.report_id.map(ReportId), @@ -236,9 +236,9 @@ impl ThreadMessage { ", &message_ids_parsed ) - .fetch_many(exec) - .try_filter_map(|e| async { - Ok(e.right().map(|x| ThreadMessage { + .fetch(exec) + .try_filter_map(|x| async { + Ok(Some(ThreadMessage { id: ThreadMessageId(x.id), thread_id: ThreadId(x.thread_id), author_id: x.author_id.map(UserId), diff --git a/src/database/models/user_item.rs b/src/database/models/user_item.rs index 67503a6b..c99f7807 100644 --- a/src/database/models/user_item.rs +++ b/src/database/models/user_item.rs @@ -263,8 +263,8 @@ impl User { ", user_id as UserId, ) - .fetch_many(exec) - .try_filter_map(|e| async { Ok(e.right().map(|m| ProjectId(m.id))) }) + .fetch(exec) + .try_filter_map(|m| async move { Ok(Some(ProjectId(m.id))) }) .try_collect::>() .await?; @@ -292,8 +292,8 @@ impl User { ", user_id as UserId, ) - .fetch_many(exec) - .try_filter_map(|e| async { Ok(e.right().map(|m| OrganizationId(m.id))) }) + .fetch(exec) + .try_filter_map(|m| async move { Ok(Some(OrganizationId(m.id))) }) .try_collect::>() .await?; @@ -316,8 +316,8 @@ impl User { ", user_id as UserId, ) - .fetch_many(exec) - .try_filter_map(|e| async { Ok(e.right().map(|m| CollectionId(m.id))) }) + .fetch(exec) + .try_filter_map(|m| async move { Ok(Some(CollectionId(m.id))) }) .try_collect::>() .await?; @@ -340,8 +340,8 @@ impl User { ", user_id as UserId, ) - .fetch_many(exec) - .try_filter_map(|e| async { Ok(e.right().map(|m| to_base62(m.code as u64))) }) + .fetch(exec) + .try_filter_map(|m| async move { Ok(Some(to_base62(m.code as u64))) }) .try_collect::>() .await?; @@ -429,8 +429,8 @@ impl User { ", id as UserId, ) - .fetch_many(&mut **transaction) - .try_filter_map(|e| async { Ok(e.right().map(|m| m.id)) }) + .fetch(&mut **transaction) + .try_filter_map(|m| async move { Ok(Some(m.id)) }) .try_collect::>() .await?; diff --git a/src/database/redis.rs b/src/database/redis.rs index 312ac251..3a7f992e 100644 --- a/src/database/redis.rs +++ b/src/database/redis.rs @@ -217,7 +217,7 @@ impl RedisPool { let mut cached_values = cached_values_raw .into_iter() .filter_map(|(key, val)| { - if Utc.timestamp(val.iat + ACTUAL_EXPIRY, 0) < current_time { + if Utc.timestamp_opt(val.iat + ACTUAL_EXPIRY, 0).unwrap() < current_time { expired_values.insert(val.key.to_string(), val); None diff --git a/src/queue/session.rs b/src/queue/session.rs index 2f7b3bfd..e49d0f86 100644 --- a/src/queue/session.rs +++ b/src/queue/session.rs @@ -98,11 +98,8 @@ impl AuthQueue { WHERE refresh_expires <= NOW() " ) - .fetch_many(&mut *transaction) - .try_filter_map(|e| async { - Ok(e.right() - .map(|x| (SessionId(x.id), x.session, UserId(x.user_id)))) - }) + .fetch(&mut *transaction) + .try_filter_map(|x| async { Ok(Some((SessionId(x.id), x.session, UserId(x.user_id)))) }) .try_collect::>() .await?; diff --git a/src/routes/internal/moderation.rs b/src/routes/internal/moderation.rs index d422404c..c52a33b7 100644 --- a/src/routes/internal/moderation.rs +++ b/src/routes/internal/moderation.rs @@ -66,8 +66,8 @@ pub async fn get_projects( ProjectStatus::Processing.as_str(), count.count as i64 ) - .fetch_many(&pool) - .try_filter_map(|e| async { Ok(e.right().map(|m| database::models::ProjectId(m.id))) }) + .fetch(&pool) + .try_filter_map(|m| async move { Ok(Some(database::models::ProjectId(m.id))) }) .try_collect::>() .await?; diff --git a/src/routes/v3/organizations.rs b/src/routes/v3/organizations.rs index abe9b5b1..79498056 100644 --- a/src/routes/v3/organizations.rs +++ b/src/routes/v3/organizations.rs @@ -90,8 +90,8 @@ pub async fn organization_projects_get( possible_organization_id.map(|x| x as i64), info ) - .fetch_many(&pool) - .try_filter_map(|e| async { Ok(e.right().map(|m| crate::database::models::ProjectId(m.id))) }) + .fetch(&pool) + .try_filter_map(|m| async move { Ok(Some(crate::database::models::ProjectId(m.id))) }) .try_collect::>() .await?; @@ -594,8 +594,8 @@ pub async fn organization_delete( ", organization.id as database::models::ids::OrganizationId ) - .fetch_many(&mut *transaction) - .try_filter_map(|e| async { Ok(e.right().map(|c| crate::database::models::TeamId(c.id))) }) + .fetch(&mut *transaction) + .try_filter_map(|c| async move { Ok(Some(crate::database::models::TeamId(c.id))) }) .try_collect::>() .await?; diff --git a/src/routes/v3/projects.rs b/src/routes/v3/projects.rs index 646940c4..0ccceb30 100644 --- a/src/routes/v3/projects.rs +++ b/src/routes/v3/projects.rs @@ -101,8 +101,8 @@ pub async fn random_projects_get( .map(|x| x.to_string()) .collect::>(), ) - .fetch_many(&pool) - .try_filter_map(|e| async { Ok(e.right().map(|m| db_ids::ProjectId(m.id))) }) + .fetch(&pool) + .try_filter_map(|m| async move { Ok(Some(db_ids::ProjectId(m.id))) }) .try_collect::>() .await?; @@ -436,8 +436,8 @@ pub async fn project_edit( ", project_item.inner.team_id as db_ids::TeamId ) - .fetch_many(&mut *transaction) - .try_filter_map(|e| async { Ok(e.right().map(|c| db_models::UserId(c.id))) }) + .fetch(&mut *transaction) + .try_filter_map(|c| async move { Ok(Some(db_models::UserId(c.id))) }) .try_collect::>() .await?; diff --git a/src/routes/v3/reports.rs b/src/routes/v3/reports.rs index 3485d9fd..7909fbea 100644 --- a/src/routes/v3/reports.rs +++ b/src/routes/v3/reports.rs @@ -261,11 +261,8 @@ pub async fn reports( ", count.count as i64 ) - .fetch_many(&pool) - .try_filter_map(|e| async { - Ok(e.right() - .map(|m| crate::database::models::ids::ReportId(m.id))) - }) + .fetch(&pool) + .try_filter_map(|m| async move { Ok(Some(crate::database::models::ids::ReportId(m.id))) }) .try_collect::>() .await? } else { @@ -279,11 +276,8 @@ pub async fn reports( user.id.0 as i64, count.count as i64 ) - .fetch_many(&pool) - .try_filter_map(|e| async { - Ok(e.right() - .map(|m| crate::database::models::ids::ReportId(m.id))) - }) + .fetch(&pool) + .try_filter_map(|m| async move { Ok(Some(crate::database::models::ids::ReportId(m.id))) }) .try_collect::>() .await? }; diff --git a/src/routes/v3/threads.rs b/src/routes/v3/threads.rs index 8f1ca939..5bd6d1f6 100644 --- a/src/routes/v3/threads.rs +++ b/src/routes/v3/threads.rs @@ -131,19 +131,17 @@ pub async fn filter_authorized_threads( &*project_thread_ids, user_id as database::models::ids::UserId, ) - .fetch_many(pool) - .try_for_each(|e| { - if let Some(row) = e.right() { - check_threads.retain(|x| { - let bool = x.project_id.map(|x| x.0) == Some(row.id); - - if bool { - return_threads.push(x.clone()); - } + .fetch(pool) + .try_for_each(|row| { + check_threads.retain(|x| { + let bool = x.project_id.map(|x| x.0) == Some(row.id); - !bool - }); - } + if bool { + return_threads.push(x.clone()); + } + + !bool + }); futures::future::ready(Ok(())) }) @@ -167,19 +165,17 @@ pub async fn filter_authorized_threads( &*project_thread_ids, user_id as database::models::ids::UserId, ) - .fetch_many(pool) - .try_for_each(|e| { - if let Some(row) = e.right() { - check_threads.retain(|x| { - let bool = x.project_id.map(|x| x.0) == Some(row.id); - - if bool { - return_threads.push(x.clone()); - } + .fetch(pool) + .try_for_each(|row| { + check_threads.retain(|x| { + let bool = x.project_id.map(|x| x.0) == Some(row.id); - !bool - }); - } + if bool { + return_threads.push(x.clone()); + } + + !bool + }); futures::future::ready(Ok(())) }) @@ -201,19 +197,17 @@ pub async fn filter_authorized_threads( &*report_thread_ids, user_id as database::models::ids::UserId, ) - .fetch_many(pool) - .try_for_each(|e| { - if let Some(row) = e.right() { - check_threads.retain(|x| { - let bool = x.report_id.map(|x| x.0) == Some(row.id); - - if bool { - return_threads.push(x.clone()); - } + .fetch(pool) + .try_for_each(|row| { + check_threads.retain(|x| { + let bool = x.report_id.map(|x| x.0) == Some(row.id); - !bool - }); - } + if bool { + return_threads.push(x.clone()); + } + + !bool + }); futures::future::ready(Ok(())) }) diff --git a/src/routes/v3/users.rs b/src/routes/v3/users.rs index 7ff0b26b..ecef7263 100644 --- a/src/routes/v3/users.rs +++ b/src/routes/v3/users.rs @@ -627,11 +627,8 @@ pub async fn user_follows( ", id as crate::database::models::ids::UserId, ) - .fetch_many(&pool) - .try_filter_map(|e| async { - Ok(e.right() - .map(|m| crate::database::models::ProjectId(m.mod_id))) - }) + .fetch(&pool) + .try_filter_map(|m| async move { Ok(Some(crate::database::models::ProjectId(m.mod_id))) }) .try_collect::>() .await?; diff --git a/src/routes/v3/version_creation.rs b/src/routes/v3/version_creation.rs index dd744cec..c78339c0 100644 --- a/src/routes/v3/version_creation.rs +++ b/src/routes/v3/version_creation.rs @@ -387,8 +387,8 @@ async fn version_create_inner( ", builder.project_id as crate::database::models::ids::ProjectId ) - .fetch_many(&mut **transaction) - .try_filter_map(|e| async { Ok(e.right().map(|m| models::ids::UserId(m.follower_id))) }) + .fetch(&mut **transaction) + .try_filter_map(|m| async move { Ok(Some(models::ids::UserId(m.follower_id))) }) .try_collect::>() .await?; diff --git a/src/search/indexing/local_import.rs b/src/search/indexing/local_import.rs index c5ecb942..c8993a67 100644 --- a/src/search/indexing/local_import.rs +++ b/src/search/indexing/local_import.rs @@ -49,9 +49,9 @@ pub async fn index_local(pool: &PgPool) -> Result, Inde .map(|x| x.to_string()) .collect::>(), ) - .fetch_many(pool) - .try_filter_map(|e| async { - Ok(e.right().map(|m| { + .fetch(pool) + .try_filter_map(|m| async { + Ok(Some( PartialProject { id: ProjectId(m.id), @@ -65,7 +65,7 @@ pub async fn index_local(pool: &PgPool) -> Result, Inde slug: m.slug, color: m.color, license: m.license, - }})) + })) }) .try_collect::>() .await?; diff --git a/src/util/extract.rs b/src/util/extract.rs index 9089bc63..671f6e23 100644 --- a/src/util/extract.rs +++ b/src/util/extract.rs @@ -1,4 +1,3 @@ -pub use axum::extract::ConnectInfo; use axum::extract::FromRequest; use axum::extract::FromRequestParts; use axum::response::{IntoResponse, Response}; @@ -33,9 +32,9 @@ pub struct Query(pub T); #[from_request(via(axum::Extension), rejection(crate::routes::ApiError))] pub struct Extension(pub T); -// #[derive(FromRequest, FromRequestParts)] -// #[from_request(via(axum::extract::ConnectInfo), rejection(crate::routes::ApiError))] -// pub struct ConnectInfo(pub T); +#[derive(FromRequest, FromRequestParts)] +#[from_request(via(axum::extract::ConnectInfo), rejection(crate::routes::ApiError))] +pub struct ConnectInfo(pub T); #[derive(FromRequest)] #[from_request(rejection(crate::routes::ApiError))] diff --git a/src/validate/fabric.rs b/src/validate/fabric.rs index 2ee44753..f72349e9 100644 --- a/src/validate/fabric.rs +++ b/src/validate/fabric.rs @@ -1,5 +1,5 @@ use crate::validate::{SupportedGameVersions, ValidationError, ValidationResult}; -use chrono::{DateTime, NaiveDateTime, Utc}; +use chrono::{TimeZone, Utc}; use std::io::Cursor; use zip::ZipArchive; @@ -20,10 +20,7 @@ impl super::Validator for FabricValidator { fn get_supported_game_versions(&self) -> SupportedGameVersions { // Time since release of 18w49a, the first fabric version - SupportedGameVersions::PastDate(DateTime::from_naive_utc_and_offset( - NaiveDateTime::from_timestamp_opt(1543969469, 0).unwrap(), - Utc, - )) + SupportedGameVersions::PastDate(Utc.timestamp_opt(1543969469, 0).unwrap()) } fn validate( diff --git a/src/validate/forge.rs b/src/validate/forge.rs index 04355fcd..6402b4b3 100644 --- a/src/validate/forge.rs +++ b/src/validate/forge.rs @@ -1,5 +1,5 @@ use crate::validate::{SupportedGameVersions, ValidationError, ValidationResult}; -use chrono::{DateTime, NaiveDateTime, Utc}; +use chrono::{TimeZone, Utc}; use std::io::Cursor; use zip::ZipArchive; @@ -20,10 +20,7 @@ impl super::Validator for ForgeValidator { fn get_supported_game_versions(&self) -> SupportedGameVersions { // Time since release of 1.13, the first forge version which uses the new TOML system - SupportedGameVersions::PastDate(DateTime::::from_naive_utc_and_offset( - NaiveDateTime::from_timestamp_opt(1540122067, 0).unwrap(), - Utc, - )) + SupportedGameVersions::PastDate(Utc.timestamp_opt(1540122067, 0).unwrap()) } fn validate( @@ -58,14 +55,8 @@ impl super::Validator for LegacyForgeValidator { fn get_supported_game_versions(&self) -> SupportedGameVersions { // Times between versions 1.5.2 to 1.12.2, which all use the legacy way of defining mods SupportedGameVersions::Range( - DateTime::from_naive_utc_and_offset( - NaiveDateTime::from_timestamp_opt(1366818300, 0).unwrap(), - Utc, - ), - DateTime::from_naive_utc_and_offset( - NaiveDateTime::from_timestamp_opt(1505810340, 0).unwrap(), - Utc, - ), + Utc.timestamp_opt(1366818300, 0).unwrap(), + Utc.timestamp_opt(1505810340, 0).unwrap(), ) } diff --git a/src/validate/quilt.rs b/src/validate/quilt.rs index 66741b8b..3088d8c8 100644 --- a/src/validate/quilt.rs +++ b/src/validate/quilt.rs @@ -1,5 +1,5 @@ use crate::validate::{SupportedGameVersions, ValidationError, ValidationResult}; -use chrono::{DateTime, NaiveDateTime, Utc}; +use chrono::{TimeZone, Utc}; use std::io::Cursor; use zip::ZipArchive; @@ -19,10 +19,7 @@ impl super::Validator for QuiltValidator { } fn get_supported_game_versions(&self) -> SupportedGameVersions { - SupportedGameVersions::PastDate(DateTime::from_naive_utc_and_offset( - NaiveDateTime::from_timestamp_opt(1646070100, 0).unwrap(), - Utc, - )) + SupportedGameVersions::PastDate(Utc.timestamp_opt(1646070100, 0).unwrap()) } fn validate( diff --git a/src/validate/resourcepack.rs b/src/validate/resourcepack.rs index 97f041de..3b6674a2 100644 --- a/src/validate/resourcepack.rs +++ b/src/validate/resourcepack.rs @@ -1,5 +1,5 @@ use crate::validate::{SupportedGameVersions, ValidationError, ValidationResult}; -use chrono::{DateTime, NaiveDateTime, Utc}; +use chrono::{TimeZone, Utc}; use std::io::Cursor; use zip::ZipArchive; @@ -20,10 +20,7 @@ impl super::Validator for PackValidator { fn get_supported_game_versions(&self) -> SupportedGameVersions { // Time since release of 13w24a which replaced texture packs with resource packs - SupportedGameVersions::PastDate(DateTime::from_naive_utc_and_offset( - NaiveDateTime::from_timestamp_opt(1371137542, 0).unwrap(), - Utc, - )) + SupportedGameVersions::PastDate(Utc.timestamp_opt(1371137542, 0).unwrap()) } fn validate( @@ -58,14 +55,8 @@ impl super::Validator for TexturePackValidator { fn get_supported_game_versions(&self) -> SupportedGameVersions { // a1.2.2a to 13w23b SupportedGameVersions::Range( - DateTime::from_naive_utc_and_offset( - NaiveDateTime::from_timestamp_opt(1289339999, 0).unwrap(), - Utc, - ), - DateTime::from_naive_utc_and_offset( - NaiveDateTime::from_timestamp_opt(1370651522, 0).unwrap(), - Utc, - ), + Utc.timestamp_opt(1289339999, 0).unwrap(), + Utc.timestamp_opt(1370651522, 0).unwrap(), ) }