countAttempts method
Future<int>
countAttempts(
- Session session, {
- required String key,
- Transaction? transaction,
override
Counts attempts for key within the configured window, or all time.
Implementation
@override
Future<int> countAttempts(
final Session session, {
required final String key,
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.key.equals(key);
if (config.timeframe != null) {
final oldestRelevantAttemptTimestamp = clock.now().subtract(
config.timeframe!,
);
expression &= t.attemptedAt > oldestRelevantAttemptTimestamp;
}
return expression;
},
transaction: transaction,
);
}