You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
// casting current_time() to i64 will overflow in the year 2262
140
-
let current_time_plus_hour = (current_time()asi64) + HOUR_IN_SECONDS;
145
+
let current_time_plus_hour = i64::try_from(current_time()).unwrap().saturating_add(HOUR_IN_SECONDS);
141
146
142
147
// get tracker key that is valid for at least one hour from now
143
148
query_as::<_,TrackerKey>("SELECT tracker_key AS 'key', date_expiry AS valid_until FROM torrust_tracker_keys WHERE user_id = ? AND date_expiry > ? ORDER BY date_expiry DESC")
@@ -233,7 +238,7 @@ impl Database for MysqlDatabase {
233
238
.bind(category_name)
234
239
.execute(&self.pool)
235
240
.await
236
-
.map(|v| v.last_insert_id()asi64)
241
+
.map(|v| i64::try_from(v.last_insert_id()).expect("last ID is larger than i64"))
237
242
.map_err(|e| match e {
238
243
sqlx::Error::Database(err) => {
239
244
if err.message().contains("UNIQUE"){
@@ -325,13 +330,13 @@ impl Database for MysqlDatabase {
325
330
i += 1;
326
331
}
327
332
}
328
-
if !category_filters.is_empty(){
333
+
if category_filters.is_empty(){
334
+
String::new()
335
+
}else{
329
336
format!(
330
337
"INNER JOIN torrust_categories tc ON tt.category_id = tc.category_id AND ({}) ",
331
338
category_filters
332
339
)
333
-
}else{
334
-
String::new()
335
340
}
336
341
}else{
337
342
String::new()
@@ -365,18 +370,19 @@ impl Database for MysqlDatabase {
365
370
366
371
let res:Vec<TorrentListing> = sqlx::query_as::<_,TorrentListing>(&query_string)
367
372
.bind(title)
368
-
.bind(offset asi64)
373
+
.bind(i64::saturating_add_unsigned(0, offset))
369
374
.bind(limit)
370
375
.fetch_all(&self.pool)
371
376
.await
372
377
.map_err(|_| database::Error::Error)?;
373
378
374
379
Ok(TorrentsResponse{
375
-
total: countasu32,
380
+
total:u32::try_from(count).expect("variable `count` is larger than u32"),
376
381
results: res,
377
382
})
378
383
}
379
384
385
+
#[allow(clippy::too_many_lines)]
380
386
asyncfninsert_torrent_and_get_id(
381
387
&self,
382
388
torrent:&Torrent,
@@ -416,7 +422,7 @@ impl Database for MysqlDatabase {
416
422
.bind(root_hash)
417
423
.execute(&self.pool)
418
424
.await
419
-
.map(|v| v.last_insert_id()asi64)
425
+
.map(|v| i64::try_from(v.last_insert_id()).expect("last ID is larger than i64"))
0 commit comments