Skip to content

Commit 0855fa3

Browse files
authored
admin/render_og_images: Simplify query construction (#11860)
There is no need for the duplicate prefix filter. We can just reuse the `build_query()` fn by moving the `.offset()` call out of it.
1 parent 6b77867 commit 0855fa3

File tree

1 file changed

+5
-9
lines changed

1 file changed

+5
-9
lines changed

src/bin/crates-admin/render_og_images.rs

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ pub async fn run(opts: Opts) -> Result<()> {
3636
info!("Starting OG image rendering with options: {opts:?}");
3737

3838
// Helper function to build query
39-
let build_query = |offset: i64| {
39+
let build_query = || {
4040
let mut query = crates::table
4141
.select(crates::name)
4242
.order(crates::name)
@@ -46,16 +46,11 @@ pub async fn run(opts: Opts) -> Result<()> {
4646
query = query.filter(crates::name.like(format!("{prefix}%")));
4747
}
4848

49-
query.offset(offset)
49+
query
5050
};
5151

5252
// Count total crates to process
53-
let mut count_query = crates::table.into_boxed();
54-
if let Some(prefix) = &opts.prefix {
55-
count_query = count_query.filter(crates::name.like(format!("{prefix}%")));
56-
}
57-
let total_crates: i64 = count_query.count().get_result(&mut conn).await?;
58-
53+
let total_crates: i64 = build_query().count().get_result(&mut conn).await?;
5954
info!("Total crates to enqueue: {total_crates}");
6055

6156
let mut offset = opts.offset.unwrap_or(0);
@@ -64,7 +59,8 @@ pub async fn run(opts: Opts) -> Result<()> {
6459

6560
loop {
6661
// Fetch batch of crate names
67-
let crate_names: Vec<String> = build_query(offset)
62+
let crate_names: Vec<String> = build_query()
63+
.offset(offset)
6864
.limit(opts.batch_size as i64)
6965
.load(&mut conn)
7066
.await?;

0 commit comments

Comments
 (0)