Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 8 additions & 7 deletions src/tasks/update_downloads.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,6 @@ fn collect(conn: &PgConnection, rows: &[VersionDownload]) -> QueryResult<()> {
let amt = download.downloads - download.counted;

conn.transaction::<_, diesel::result::Error, _>(|| {
// increment the number of counted downloads
update(version_downloads::table.find(download.id()))
.set(version_downloads::counted.eq(version_downloads::counted + amt))
.execute(conn)?;

// Update the total number of version downloads
let crate_id = update(versions::table.find(download.version_id))
.set(versions::downloads.eq(versions::downloads + amt))
Expand All @@ -68,12 +63,18 @@ fn collect(conn: &PgConnection, rows: &[VersionDownload]) -> QueryResult<()> {
.set(crates::downloads.eq(crates::downloads + amt))
.execute(conn)?;

// Now that everything else for this crate is done, update the global counter of total
// downloads
// Update the global counter of total downloads
update(metadata::table)
.set(metadata::total_downloads.eq(metadata::total_downloads + i64::from(amt)))
.execute(conn)?;

// Record that these downloads have been propagated to the other tables. This is done
// last, immediately before the transaction is committed, to minimize lock contention
// with counting new downloads.
update(version_downloads::table.find(download.id()))
.set(version_downloads::counted.eq(version_downloads::counted + amt))
.execute(conn)?;

Ok(())
})?;
}
Expand Down