Skip to content

Commit 3516108

Browse files
committed
worker/jobs/downloads/update_metadata: Update values in the crate_downloads table too
This is not removing the `crates` table update just yet, since we need to keep both tables in sync for now until the rest of the code is migrated to reading from the `crate_downloads` table instead.
1 parent 13d1792 commit 3516108

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

src/worker/jobs/downloads/update_metadata.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,12 @@ fn batch_update(batch_size: i64, conn: &mut PgConnection) -> QueryResult<i64> {
126126
SET downloads = crates.downloads + crate_downloads_batch.downloads
127127
FROM crate_downloads_batch
128128
WHERE crates.id = crate_downloads_batch.crate_id
129+
), updated_crate_downloads AS (
130+
-- Update the `downloads` count for each crate in the `crate_downloads` table.
131+
UPDATE crate_downloads
132+
SET downloads = crate_downloads.downloads + crate_downloads_batch.downloads
133+
FROM crate_downloads_batch
134+
WHERE crate_downloads.crate_id = crate_downloads_batch.crate_id
129135
), updated_metadata AS (
130136
-- Update the `total_downloads` count in the `metadata` table.
131137
UPDATE metadata

0 commit comments

Comments
 (0)