Skip to content

Commit 01311d9

Browse files
committed
controllers/krate/metadata: Extract load_categories() fn
1 parent 472ad84 commit 01311d9

File tree

1 file changed

+17
-11
lines changed

1 file changed

+17
-11
lines changed

src/controllers/krate/metadata.rs

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -147,17 +147,7 @@ pub async fn find_crate(
147147
};
148148

149149
let kws = load_keywords(&mut conn, &krate, include.keywords).await?;
150-
let cats = if include.categories {
151-
Some(
152-
CrateCategory::belonging_to(&krate)
153-
.inner_join(categories::table)
154-
.select(Category::as_select())
155-
.load(&mut conn)
156-
.await?,
157-
)
158-
} else {
159-
None
160-
};
150+
let cats = load_categories(&mut conn, &krate, include.categories).await?;
161151
let recent_downloads = if include.downloads {
162152
RecentCrateDownloads::belonging_to(&krate)
163153
.select(recent_crate_downloads::downloads)
@@ -275,6 +265,22 @@ fn load_keywords<'a>(
275265
async move { Ok(Some(fut.await?)) }.boxed()
276266
}
277267

268+
fn load_categories<'a>(
269+
conn: &mut AsyncPgConnection,
270+
krate: &'a Crate,
271+
includes: bool,
272+
) -> BoxFuture<'a, AppResult<Option<Vec<Category>>>> {
273+
if !includes {
274+
return always_ready(|| Ok(None)).boxed();
275+
}
276+
277+
let fut = CrateCategory::belonging_to(&krate)
278+
.inner_join(categories::table)
279+
.select(Category::as_select())
280+
.load(conn);
281+
async move { Ok(Some(fut.await?)) }.boxed()
282+
}
283+
278284
fn _load_versions_and_publishers<'a>(
279285
conn: &mut AsyncPgConnection,
280286
krate: &'a Crate,

0 commit comments

Comments
 (0)