@@ -88,6 +88,18 @@ fn collect(tx: &postgres::Transaction,
88
88
}
89
89
let amt = download. downloads - download. counted ;
90
90
91
+ // Flag this row as having been processed if we're passed the cutoff,
92
+ // and unconditionally increment the number of counted downloads.
93
+ try!( tx. execute ( "UPDATE version_downloads
94
+ SET processed = $2, counted = counted + $3
95
+ WHERE id = $1" ,
96
+ & [ id, & ( download. date < cutoff) , & amt] ) ) ;
97
+ total += amt as i64 ;
98
+
99
+ if amt == 0 {
100
+ continue
101
+ }
102
+
91
103
let crate_id = Version :: find ( tx, download. version_id ) . unwrap ( ) . crate_id ;
92
104
93
105
// Update the total number of version downloads
@@ -110,14 +122,6 @@ fn collect(tx: &postgres::Transaction,
110
122
VALUES ($1, $2, $3)" ,
111
123
& [ & crate_id, & amt, & download. date ] ) ) ;
112
124
}
113
-
114
- // Flag this row as having been processed if we're passed the cutoff,
115
- // and unconditionally increment the number of counted downloads.
116
- try!( tx. execute ( "UPDATE version_downloads
117
- SET processed = $2, counted = counted + $3
118
- WHERE id = $1" ,
119
- & [ id, & ( download. date < cutoff) , & amt] ) ) ;
120
- total += amt as i64 ;
121
125
}
122
126
123
127
// After everything else is done, update the global counter of total
@@ -267,4 +271,35 @@ mod test {
267
271
:: update ( & tx) . unwrap ( ) ;
268
272
assert_eq ! ( Version :: find( & tx, version. id) . unwrap( ) . downloads, 2 ) ;
269
273
}
274
+
275
+ #[ test]
276
+ fn set_processed_no_set_updated_at ( ) {
277
+ let conn = conn ( ) ;
278
+ let tx = conn. transaction ( ) . unwrap ( ) ;
279
+ let user = user ( & tx) ;
280
+ let krate = Crate :: find_or_insert ( & tx, "foo" , user. id , & None ,
281
+ & None , & None , & None , & [ ] , & None ,
282
+ & None , & None , None ) . unwrap ( ) ;
283
+ let version = Version :: insert ( & tx, krate. id ,
284
+ & semver:: Version :: parse ( "1.0.0" ) . unwrap ( ) ,
285
+ & HashMap :: new ( ) , & [ ] ) . unwrap ( ) ;
286
+ tx. execute ( "UPDATE versions
287
+ SET updated_at = current_date - interval '2 days'" ,
288
+ & [ ] ) . unwrap ( ) ;
289
+ tx. execute ( "UPDATE crates
290
+ SET updated_at = current_date - interval '2 days'" ,
291
+ & [ ] ) . unwrap ( ) ;
292
+ tx. execute ( "INSERT INTO version_downloads \
293
+ (version_id, downloads, counted, date, processed)
294
+ VALUES ($1, 2, 2, current_date - interval '2 days', false)" ,
295
+ & [ & version. id ] ) . unwrap ( ) ;
296
+
297
+ let version_before = Version :: find ( & tx, version. id ) . unwrap ( ) ;
298
+ let krate_before = Crate :: find ( & tx, krate. id ) . unwrap ( ) ;
299
+ :: update ( & tx) . unwrap ( ) ;
300
+ let version2 = Version :: find ( & tx, version. id ) . unwrap ( ) ;
301
+ assert_eq ! ( version2. updated_at, version_before. updated_at) ;
302
+ let krate2 = Crate :: find ( & tx, krate. id ) . unwrap ( ) ;
303
+ assert_eq ! ( krate2. updated_at, krate_before. updated_at) ;
304
+ }
270
305
}
0 commit comments