Skip to content

Commit 472ad84

Browse files
committed
controllers/krate/metadata: Extract load_keywords() fn
1 parent be018e8 commit 472ad84

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
@@ -146,17 +146,7 @@ pub async fn find_crate(
146146
)
147147
};
148148

149-
let kws = if include.keywords {
150-
Some(
151-
CrateKeyword::belonging_to(&krate)
152-
.inner_join(keywords::table)
153-
.select(Keyword::as_select())
154-
.load(&mut conn)
155-
.await?,
156-
)
157-
} else {
158-
None
159-
};
149+
let kws = load_keywords(&mut conn, &krate, include.keywords).await?;
160150
let cats = if include.categories {
161151
Some(
162152
CrateCategory::belonging_to(&krate)
@@ -269,6 +259,22 @@ fn load_default_versions_and_publishers<'a>(
269259
.boxed()
270260
}
271261

262+
fn load_keywords<'a>(
263+
conn: &mut AsyncPgConnection,
264+
krate: &'a Crate,
265+
includes: bool,
266+
) -> BoxFuture<'a, AppResult<Option<Vec<Keyword>>>> {
267+
if !includes {
268+
return always_ready(|| Ok(None)).boxed();
269+
}
270+
271+
let fut = CrateKeyword::belonging_to(&krate)
272+
.inner_join(keywords::table)
273+
.select(Keyword::as_select())
274+
.load(conn);
275+
async move { Ok(Some(fut.await?)) }.boxed()
276+
}
277+
272278
fn _load_versions_and_publishers<'a>(
273279
conn: &mut AsyncPgConnection,
274280
krate: &'a Crate,

0 commit comments

Comments
 (0)