Skip to content

Commit 79d6037

Browse files
committed
worker/jobs/expiry_notification: Simplify filter() call
Using multiple `filter()` calls is equivalent to using `.and()`, but reduces the indentation level and makes the code slightly more readable :)
1 parent 2de9d63 commit 79d6037

File tree

1 file changed

+7
-9
lines changed

1 file changed

+7
-9
lines changed

src/worker/jobs/expiry_notification.rs

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ use chrono::SecondsFormat;
66
use crates_io_worker::BackgroundJob;
77
use diesel::dsl::IntervalDsl;
88
use diesel::{
9-
dsl::now, BoolExpressionMethods, ExpressionMethods, NullableExpressionMethods, PgConnection,
10-
QueryDsl, QueryResult, RunQueryDsl, SelectableHelper,
9+
dsl::now, ExpressionMethods, NullableExpressionMethods, PgConnection, QueryDsl, QueryResult,
10+
RunQueryDsl, SelectableHelper,
1111
};
1212
use std::sync::Arc;
1313

@@ -89,15 +89,13 @@ pub fn find_tokens_expiring_within_days(
8989
) -> QueryResult<Vec<ApiToken>> {
9090
api_tokens::table
9191
.filter(api_tokens::revoked.eq(false))
92+
.filter(api_tokens::expired_at.is_not_null())
93+
// Ignore already expired tokens
94+
.filter(api_tokens::expired_at.assume_not_null().gt(now))
9295
.filter(
9396
api_tokens::expired_at
94-
.is_not_null()
95-
.and(api_tokens::expired_at.assume_not_null().gt(now)) // Ignore already expired tokens
96-
.and(
97-
api_tokens::expired_at
98-
.assume_not_null()
99-
.lt(now + days_until_expiry.num_days().day()),
100-
),
97+
.assume_not_null()
98+
.lt(now + days_until_expiry.num_days().day()),
10199
)
102100
.filter(api_tokens::expiry_notification_at.is_null())
103101
.select(ApiToken::as_select())

0 commit comments

Comments
 (0)