@@ -6,6 +6,7 @@ import 'package:_pub_shared/data/account_api.dart' as api;
66import 'package:clock/clock.dart' ;
77import 'package:gcloud/service_scope.dart' as ss;
88import 'package:logging/logging.dart' ;
9+ import 'package:pub_dev/shared/redis_cache.dart' ;
910import 'package:retry/retry.dart' ;
1011
1112import '../account/agent.dart' ;
@@ -118,19 +119,31 @@ class ConsentBackend {
118119 kind: kind,
119120 args: args,
120121 );
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 ()) {
126139 // 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 ()) {
129142 // non-expired entries just re-send the notification
130- return await _sendNotification (activeAgent.displayId, old );
143+ return await _sendNotification (activeAgent.displayId, existing );
131144 } else {
132145 return api.InviteStatus (
133- emailSent: false , nextNotification: old .nextNotification);
146+ emailSent: false , nextNotification: existing .nextNotification);
134147 }
135148 }
136149 // Create a new entry.
@@ -144,6 +157,7 @@ class ConsentBackend {
144157 consent,
145158 auditLogRecord,
146159 ]);
160+ await dedupCacheEntry.set (consent.consentId);
147161 return await _sendNotification (activeAgent.displayId, consent);
148162 });
149163 }
0 commit comments