@@ -6,6 +6,7 @@ import 'package:_pub_shared/data/account_api.dart' as api;
6
6
import 'package:clock/clock.dart' ;
7
7
import 'package:gcloud/service_scope.dart' as ss;
8
8
import 'package:logging/logging.dart' ;
9
+ import 'package:pub_dev/shared/redis_cache.dart' ;
9
10
import 'package:retry/retry.dart' ;
10
11
11
12
import '../account/agent.dart' ;
@@ -118,19 +119,31 @@ class ConsentBackend {
118
119
kind: kind,
119
120
args: args,
120
121
);
121
- final query = _db.query <Consent >()..filter ('dedupId =' , dedupId);
122
- final list = await query.run ().toList ();
123
- if (list.isNotEmpty) {
124
- final old = list.first;
125
- if (old.isExpired ()) {
122
+ Consent ? existing;
123
+
124
+ final dedupCacheEntry = cache.consentDedupLookup (dedupId);
125
+ final cachedConsentId = await dedupCacheEntry.get ();
126
+ if (cachedConsentId != null ) {
127
+ final key = _db.emptyKey.append (Consent , id: cachedConsentId);
128
+ existing = await _db.lookupOrNull <Consent >(key);
129
+ }
130
+ if (existing == null ) {
131
+ final query = _db.query <Consent >()
132
+ ..filter ('dedupId =' , dedupId)
133
+ ..limit (1 );
134
+ final list = await query.run ().toList ();
135
+ existing = list.singleOrNull;
136
+ }
137
+ if (existing != null ) {
138
+ if (existing.isExpired ()) {
126
139
// expired entries should be deleted
127
- await _delete (old , (a) => a.onExpire (old ));
128
- } else if (old .shouldNotify ()) {
140
+ await _delete (existing , (a) => a.onExpire (existing ! ));
141
+ } else if (existing .shouldNotify ()) {
129
142
// non-expired entries just re-send the notification
130
- return await _sendNotification (activeAgent.displayId, old );
143
+ return await _sendNotification (activeAgent.displayId, existing );
131
144
} else {
132
145
return api.InviteStatus (
133
- emailSent: false , nextNotification: old .nextNotification);
146
+ emailSent: false , nextNotification: existing .nextNotification);
134
147
}
135
148
}
136
149
// Create a new entry.
@@ -144,6 +157,7 @@ class ConsentBackend {
144
157
consent,
145
158
auditLogRecord,
146
159
]);
160
+ await dedupCacheEntry.set (consent.consentId);
147
161
return await _sendNotification (activeAgent.displayId, consent);
148
162
});
149
163
}
0 commit comments