Skip to content

Commit b51da84

Browse files
authored
controllers/summary: Remove unnecessary .is_empty() conditions (#9862)
If we pass in an empty array then so be it, but there is no need for the boxed and mutated queries here :)
1 parent dd2863e commit b51da84

File tree

1 file changed

+4
-14
lines changed

1 file changed

+4
-14
lines changed

src/controllers/summary.rs

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -96,34 +96,24 @@ pub async fn summary(state: AppState) -> AppResult<Json<Value>> {
9696
.load(&mut conn)
9797
.await?;
9898

99-
let mut most_downloaded_query = crates::table
99+
let most_downloaded = crates::table
100100
.inner_join(crate_downloads::table)
101101
.left_join(recent_crate_downloads::table)
102102
.left_join(default_versions::table)
103103
.left_join(versions::table.on(default_versions::version_id.eq(versions::id)))
104-
.into_boxed();
105-
if !config.excluded_crate_names.is_empty() {
106-
most_downloaded_query =
107-
most_downloaded_query.filter(crates::name.ne_all(&config.excluded_crate_names));
108-
}
109-
let most_downloaded = most_downloaded_query
104+
.filter(crates::name.ne_all(&config.excluded_crate_names))
110105
.then_order_by(crate_downloads::downloads.desc())
111106
.select(selection)
112107
.limit(10)
113108
.load(&mut conn)
114109
.await?;
115110

116-
let mut most_recently_downloaded_query = crates::table
111+
let most_recently_downloaded = crates::table
117112
.inner_join(crate_downloads::table)
118113
.inner_join(recent_crate_downloads::table)
119114
.left_join(default_versions::table)
120115
.left_join(versions::table.on(default_versions::version_id.eq(versions::id)))
121-
.into_boxed();
122-
if !config.excluded_crate_names.is_empty() {
123-
most_recently_downloaded_query = most_recently_downloaded_query
124-
.filter(crates::name.ne_all(&config.excluded_crate_names));
125-
}
126-
let most_recently_downloaded = most_recently_downloaded_query
116+
.filter(crates::name.ne_all(&config.excluded_crate_names))
127117
.then_order_by(recent_crate_downloads::downloads.desc())
128118
.select(selection)
129119
.limit(10)

0 commit comments

Comments
 (0)