@@ -828,7 +828,10 @@ pub fn download(req: &mut Request) -> CargoResult<Response> {
828
828
let crate_name = & req. params ( ) [ "crate_id" ] ;
829
829
let version = & req. params ( ) [ "version" ] ;
830
830
831
- try!( increment_download_counts ( req, crate_name, version) ) ;
831
+ match increment_download_counts ( req, crate_name, version) {
832
+ _ => { } // do not try, ignore failures
833
+ }
834
+
832
835
let redirect_url = format ! ( "https://{}/crates/{}/{}-{}.crate" ,
833
836
req. app( ) . bucket. host( ) ,
834
837
crate_name, crate_name, version) ;
@@ -853,32 +856,34 @@ fn increment_download_counts(req: &Request, crate_name: &str, version: &str) ->
853
856
AND versions.num = $2
854
857
LIMIT 1" ) ) ;
855
858
let rows = try!( stmt. query ( & [ & crate_name, & version] ) ) ;
856
- let row = try!( rows. iter ( ) . next ( ) . chain_error ( || {
857
- human ( "crate or version not found" )
858
- } ) ) ;
859
- let version_id: i32 = row. get ( "version_id" ) ;
860
- let now = :: now ( ) ;
861
-
862
- // Bump download counts.
863
- //
864
- // Note that this is *not* an atomic update, and that's somewhat
865
- // intentional. It doesn't appear that postgres supports an atomic update of
866
- // a counter, so we just do the hopefully "least racy" thing. This is
867
- // largely ok because these download counters are just that, counters. No
868
- // need to have super high-fidelity counter.
869
- //
870
- // Also, we only update the counter for *today*, nothing else. We have lots
871
- // of other counters, but they're all updated later on via the
872
- // update-downloads script.
873
- let amt = try!( tx. execute ( "UPDATE version_downloads
874
- SET downloads = downloads + 1
875
- WHERE version_id = $1 AND date($2) = date(date)" ,
876
- & [ & version_id, & now] ) ) ;
877
- if amt == 0 {
878
- try!( tx. execute ( "INSERT INTO version_downloads
879
- (version_id) VALUES ($1)" , & [ & version_id] ) ) ;
859
+ match rows. iter ( ) . next ( ) {
860
+ None => Err ( human ( "crate or version not found" ) ) ,
861
+ Some ( row) => {
862
+ let version_id: i32 = row. get ( "version_id" ) ;
863
+ let now = :: now ( ) ;
864
+
865
+ // Bump download counts.
866
+ //
867
+ // Note that this is *not* an atomic update, and that's somewhat
868
+ // intentional. It doesn't appear that postgres supports an atomic update of
869
+ // a counter, so we just do the hopefully "least racy" thing. This is
870
+ // largely ok because these download counters are just that, counters. No
871
+ // need to have super high-fidelity counter.
872
+ //
873
+ // Also, we only update the counter for *today*, nothing else. We have lots
874
+ // of other counters, but they're all updated later on via the
875
+ // update-downloads script.
876
+ let amt = try!( tx. execute ( "UPDATE version_downloads
877
+ SET downloads = downloads + 1
878
+ WHERE version_id = $1 AND date($2) = date(date)" ,
879
+ & [ & version_id, & now] ) ) ;
880
+ if amt == 0 {
881
+ try!( tx. execute ( "INSERT INTO version_downloads
882
+ (version_id) VALUES ($1)" , & [ & version_id] ) ) ;
883
+ }
884
+ Ok ( ( ) )
885
+ }
880
886
}
881
- Ok ( ( ) )
882
887
}
883
888
884
889
/// Handles the `GET /crates/:crate_id/downloads` route.
0 commit comments