@@ -55,7 +55,7 @@ impl PublishRateLimit {
55
55
uploader : i32 ,
56
56
now : NaiveDateTime ,
57
57
conn : & PgConnection ,
58
- ) -> AppResult < Bucket > {
58
+ ) -> QueryResult < Bucket > {
59
59
use self :: publish_limit_buckets:: dsl:: * ;
60
60
use diesel:: sql_types:: { Double , Interval , Text , Timestamp } ;
61
61
@@ -93,7 +93,6 @@ impl PublishRateLimit {
93
93
. eq ( last_refill + self . refill_rate ( ) . into_sql :: < Interval > ( ) * tokens_to_add) ,
94
94
) )
95
95
. get_result ( conn)
96
- . map_err ( Into :: into)
97
96
}
98
97
99
98
fn refill_rate ( & self ) -> PgInterval {
@@ -108,7 +107,7 @@ mod tests {
108
107
use crate :: test_util:: * ;
109
108
110
109
#[ test]
111
- fn take_token_with_no_bucket_creates_new_one ( ) -> AppResult < ( ) > {
110
+ fn take_token_with_no_bucket_creates_new_one ( ) -> QueryResult < ( ) > {
112
111
let conn = pg_connection ( ) ;
113
112
let now = now ( ) ;
114
113
@@ -139,7 +138,7 @@ mod tests {
139
138
}
140
139
141
140
#[ test]
142
- fn take_token_with_existing_bucket_modifies_existing_bucket ( ) -> AppResult < ( ) > {
141
+ fn take_token_with_existing_bucket_modifies_existing_bucket ( ) -> QueryResult < ( ) > {
143
142
let conn = pg_connection ( ) ;
144
143
let now = now ( ) ;
145
144
@@ -159,7 +158,7 @@ mod tests {
159
158
}
160
159
161
160
#[ test]
162
- fn take_token_after_delay_refills ( ) -> AppResult < ( ) > {
161
+ fn take_token_after_delay_refills ( ) -> QueryResult < ( ) > {
163
162
let conn = pg_connection ( ) ;
164
163
let now = now ( ) ;
165
164
@@ -180,12 +179,13 @@ mod tests {
180
179
}
181
180
182
181
#[ test]
183
- fn refill_subsecond_rate ( ) -> AppResult < ( ) > {
182
+ fn refill_subsecond_rate ( ) -> QueryResult < ( ) > {
184
183
let conn = pg_connection ( ) ;
185
184
// Subsecond rates have floating point rounding issues, so use a known
186
185
// timestamp that rounds fine
187
186
let now =
188
- NaiveDateTime :: parse_from_str ( "2019-03-19T21:11:24.620401" , "%Y-%m-%dT%H:%M:%S%.f" ) ?;
187
+ NaiveDateTime :: parse_from_str ( "2019-03-19T21:11:24.620401" , "%Y-%m-%dT%H:%M:%S%.f" )
188
+ . unwrap ( ) ;
189
189
190
190
let rate = PublishRateLimit {
191
191
rate : Duration :: from_millis ( 100 ) ,
@@ -204,7 +204,7 @@ mod tests {
204
204
}
205
205
206
206
#[ test]
207
- fn last_refill_always_advanced_by_multiple_of_rate ( ) -> AppResult < ( ) > {
207
+ fn last_refill_always_advanced_by_multiple_of_rate ( ) -> QueryResult < ( ) > {
208
208
let conn = pg_connection ( ) ;
209
209
let now = now ( ) ;
210
210
@@ -225,7 +225,7 @@ mod tests {
225
225
}
226
226
227
227
#[ test]
228
- fn zero_tokens_returned_when_user_has_no_tokens_left ( ) -> AppResult < ( ) > {
228
+ fn zero_tokens_returned_when_user_has_no_tokens_left ( ) -> QueryResult < ( ) > {
229
229
let conn = pg_connection ( ) ;
230
230
let now = now ( ) ;
231
231
@@ -248,7 +248,7 @@ mod tests {
248
248
}
249
249
250
250
#[ test]
251
- fn a_user_with_no_tokens_gets_a_token_after_exactly_rate ( ) -> AppResult < ( ) > {
251
+ fn a_user_with_no_tokens_gets_a_token_after_exactly_rate ( ) -> QueryResult < ( ) > {
252
252
let conn = pg_connection ( ) ;
253
253
let now = now ( ) ;
254
254
@@ -270,7 +270,7 @@ mod tests {
270
270
}
271
271
272
272
#[ test]
273
- fn tokens_never_refill_past_burst ( ) -> AppResult < ( ) > {
273
+ fn tokens_never_refill_past_burst ( ) -> QueryResult < ( ) > {
274
274
let conn = pg_connection ( ) ;
275
275
let now = now ( ) ;
276
276
@@ -292,7 +292,7 @@ mod tests {
292
292
}
293
293
294
294
#[ test]
295
- fn override_is_used_instead_of_global_burst_if_present ( ) -> AppResult < ( ) > {
295
+ fn override_is_used_instead_of_global_burst_if_present ( ) -> QueryResult < ( ) > {
296
296
let conn = pg_connection ( ) ;
297
297
let now = now ( ) ;
298
298
@@ -318,7 +318,7 @@ mod tests {
318
318
Ok ( ( ) )
319
319
}
320
320
321
- fn new_user ( conn : & PgConnection , gh_login : & str ) -> AppResult < i32 > {
321
+ fn new_user ( conn : & PgConnection , gh_login : & str ) -> QueryResult < i32 > {
322
322
use crate :: models:: NewUser ;
323
323
324
324
let user = NewUser {
@@ -329,15 +329,18 @@ mod tests {
329
329
Ok ( user. id )
330
330
}
331
331
332
- fn new_user_bucket ( conn : & PgConnection , tokens : i32 , now : NaiveDateTime ) -> AppResult < Bucket > {
332
+ fn new_user_bucket (
333
+ conn : & PgConnection ,
334
+ tokens : i32 ,
335
+ now : NaiveDateTime ,
336
+ ) -> QueryResult < Bucket > {
333
337
diesel:: insert_into ( publish_limit_buckets:: table)
334
338
. values ( Bucket {
335
339
user_id : new_user ( conn, "new_user" ) ?,
336
340
tokens,
337
341
last_refill : now,
338
342
} )
339
343
. get_result ( conn)
340
- . map_err ( Into :: into)
341
344
}
342
345
343
346
/// Strips ns precision from `Utc::now`. PostgreSQL only has microsecond
0 commit comments