Skip to content

Commit e15ebc8

Browse files
authored
admin/render_og_images: Fix query construction (#11866)
Using `.order()` in `.count()` queries appears to make Diesel unhappy...
1 parent 27278f8 commit e15ebc8

File tree

1 file changed

+9
-8
lines changed

1 file changed

+9
-8
lines changed

src/bin/crates-admin/render_og_images.rs

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use anyhow::Result;
1+
use anyhow::{Context, Result};
22
use crates_io::db;
33
use crates_io::schema::{background_jobs, crates};
44
use crates_io::worker::jobs::GenerateOgImage;
@@ -37,10 +37,7 @@ pub async fn run(opts: Opts) -> Result<()> {
3737

3838
// Helper function to build query
3939
let build_query = || {
40-
let mut query = crates::table
41-
.select(crates::name)
42-
.order(crates::name)
43-
.into_boxed();
40+
let mut query = crates::table.select(crates::name).into_boxed();
4441

4542
if let Some(prefix) = &opts.prefix {
4643
query = query.filter(crates::name.like(format!("{prefix}%")));
@@ -50,7 +47,8 @@ pub async fn run(opts: Opts) -> Result<()> {
5047
};
5148

5249
// Count total crates to process
53-
let total_crates: i64 = build_query().count().get_result(&mut conn).await?;
50+
let result = build_query().count().get_result(&mut conn).await;
51+
let total_crates: i64 = result.context("Failed to count matching crates")?;
5452
info!("Total crates to enqueue: {total_crates}");
5553

5654
let mut offset = opts.offset.unwrap_or(0);
@@ -60,10 +58,12 @@ pub async fn run(opts: Opts) -> Result<()> {
6058
loop {
6159
// Fetch batch of crate names
6260
let crate_names: Vec<String> = build_query()
61+
.order(crates::name)
6362
.offset(offset)
6463
.limit(opts.batch_size as i64)
6564
.load(&mut conn)
66-
.await?;
65+
.await
66+
.context("Failed to load crate names")?;
6767

6868
if crate_names.is_empty() {
6969
break;
@@ -93,7 +93,8 @@ pub async fn run(opts: Opts) -> Result<()> {
9393
background_jobs::priority.eq(-10),
9494
))
9595
})
96-
.collect::<serde_json::Result<Vec<_>>>()?;
96+
.collect::<serde_json::Result<Vec<_>>>()
97+
.context("Failed to enqueue background jobs")?;
9798

9899
// Batch insert all jobs
99100
let result = diesel::insert_into(background_jobs::table)

0 commit comments

Comments
 (0)