countAttempts method
Future<int>
countAttempts(
- Session session, {
- required T nonce,
- Transaction? transaction,
override
Counts the number of attempts for the given nonce.
nonce is the unique identifier for the request (e.g., email, request ID, token).
Implementation
@override
Future<int> countAttempts(
final Session session, {
required final T nonce,
final Transaction? transaction,
}) async {
return await RateLimitedRequestAttempt.db.count(
session,
where: (final t) {
var expression =
t.domain.equals(config.domain) &
t.source.equals(config.source) &
t.nonce.equals(config.nonceToString(nonce));
if (config.timeframe != null) {
final oldestRelevantAttemptTimestamp = clock.now().subtract(
config.timeframe!,
);
expression &= t.attemptedAt > oldestRelevantAttemptTimestamp;
}
return expression;
},
transaction: transaction,
);
}