Skip to content

Commit e49d324

Browse files
authored
Fix some dbService reference. (#8658)
1 parent db94a61 commit e49d324

File tree

6 files changed

+31
-20
lines changed

6 files changed

+31
-20
lines changed

app/lib/account/consent_backend.dart

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -46,10 +46,10 @@ abstract class ConsentKind {
4646
/// Represents the backend for the consent handling and authentication.
4747
class ConsentBackend {
4848
final DatastoreDB _db;
49-
final _actions = <String, ConsentAction>{
50-
ConsentKind.packageUploader: _PackageUploaderAction(),
51-
ConsentKind.publisherContact: _PublisherContactAction(),
52-
ConsentKind.publisherMember: _PublisherMemberAction(),
49+
late final _actions = <String, ConsentAction>{
50+
ConsentKind.packageUploader: _PackageUploaderAction(_db),
51+
ConsentKind.publisherContact: _PublisherContactAction(_db),
52+
ConsentKind.publisherMember: _PublisherMemberAction(_db),
5353
};
5454

5555
ConsentBackend(this._db);
@@ -316,6 +316,9 @@ abstract class ConsentAction {
316316

317317
/// Callbacks for package uploader consents.
318318
class _PackageUploaderAction extends ConsentAction {
319+
final DatastoreDB _db;
320+
_PackageUploaderAction(this._db);
321+
319322
@override
320323
Future<void> onAccept(Consent consent) async {
321324
final packageName = consent.args![0];
@@ -335,7 +338,7 @@ class _PackageUploaderAction extends ConsentAction {
335338
@override
336339
Future<void> onReject(Consent consent, User? user) async {
337340
final packageName = consent.args![0];
338-
await withRetryTransaction(dbService, (tx) async {
341+
await withRetryTransaction(_db, (tx) async {
339342
tx.insert(await AuditLogRecord.uploaderInviteRejected(
340343
fromAgent: consent.fromAgent,
341344
package: packageName,
@@ -348,7 +351,7 @@ class _PackageUploaderAction extends ConsentAction {
348351
@override
349352
Future<void> onExpire(Consent consent) async {
350353
final packageName = consent.args![0];
351-
await withRetryTransaction(dbService, (tx) async {
354+
await withRetryTransaction(_db, (tx) async {
352355
tx.insert(await AuditLogRecord.uploaderInviteExpired(
353356
fromAgent: consent.fromAgent,
354357
package: packageName,
@@ -386,6 +389,9 @@ class _PackageUploaderAction extends ConsentAction {
386389

387390
/// Callbacks for requesting permission to use e-mail as publisher contact.
388391
class _PublisherContactAction extends ConsentAction {
392+
final DatastoreDB _db;
393+
_PublisherContactAction(this._db);
394+
389395
@override
390396
Future<void> onAccept(Consent consent) async {
391397
final publisherId = consent.args![0];
@@ -400,7 +406,7 @@ class _PublisherContactAction extends ConsentAction {
400406
@override
401407
Future<void> onReject(Consent consent, User? user) async {
402408
final publisherId = consent.args![0];
403-
await withRetryTransaction(dbService, (tx) async {
409+
await withRetryTransaction(_db, (tx) async {
404410
tx.insert(await AuditLogRecord.publisherContactInviteRejected(
405411
fromAgent: consent.fromAgent,
406412
publisherId: publisherId,
@@ -414,7 +420,7 @@ class _PublisherContactAction extends ConsentAction {
414420
@override
415421
Future<void> onExpire(Consent consent) async {
416422
final publisherId = consent.args![0];
417-
await withRetryTransaction(dbService, (tx) async {
423+
await withRetryTransaction(_db, (tx) async {
418424
tx.insert(await AuditLogRecord.publisherContactInviteExpired(
419425
fromAgent: consent.fromAgent,
420426
publisherId: publisherId,
@@ -462,6 +468,9 @@ class _PublisherContactAction extends ConsentAction {
462468

463469
/// Callbacks for publisher member consents.
464470
class _PublisherMemberAction extends ConsentAction {
471+
final DatastoreDB _db;
472+
_PublisherMemberAction(this._db);
473+
465474
@override
466475
Future<void> onAccept(Consent consent) async {
467476
final publisherId = consent.args![0];
@@ -479,7 +488,7 @@ class _PublisherMemberAction extends ConsentAction {
479488
@override
480489
Future<void> onReject(Consent consent, User? user) async {
481490
final publisherId = consent.args![0];
482-
await withRetryTransaction(dbService, (tx) async {
491+
await withRetryTransaction(_db, (tx) async {
483492
tx.insert(await AuditLogRecord.publisherMemberInviteRejected(
484493
fromAgent: consent.fromAgent,
485494
publisherId: publisherId,
@@ -492,7 +501,7 @@ class _PublisherMemberAction extends ConsentAction {
492501
@override
493502
Future<void> onExpire(Consent consent) async {
494503
final publisherId = consent.args![0];
495-
await withRetryTransaction(dbService, (tx) async {
504+
await withRetryTransaction(_db, (tx) async {
496505
tx.insert(await AuditLogRecord.publisherMemberInviteExpired(
497506
fromAgent: consent.fromAgent,
498507
publisherId: publisherId,

app/lib/audit/backend.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@ class AuditBackend {
179179
window = Duration(minutes: 2);
180180
}
181181

182-
final query = dbService.query<AuditLogRecord>()
182+
final query = _db.query<AuditLogRecord>()
183183
..filter('created >', now.subtract(window));
184184
final current = await query.run().toList();
185185

app/lib/package/backend.dart

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,8 +117,10 @@ class PackageBackend {
117117
}))!;
118118
}
119119

120+
Stream<Package> allPackages() => db.query<Package>().run();
121+
120122
Stream<String> allPackageNames() {
121-
return db.query<Package>().run().map((p) => p.name!);
123+
return allPackages().map((p) => p.name!);
122124
}
123125

124126
/// Retrieves the packages that need to be included in sitemap.txt.

app/lib/search/backend.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@ class SearchBackend {
180180
// initial scan of packages
181181
final pool = Pool(concurrency);
182182
final futures = <Future>[];
183-
await for (final package in dbService.query<Package>().run()) {
183+
await for (final package in packageBackend.allPackages()) {
184184
if (package.isNotVisible) {
185185
continue;
186186
}

app/lib/shared/integrity.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -907,8 +907,8 @@ class IntegrityChecker {
907907
// TODO: verify fields once the other PR lands
908908

909909
if (mc.appealedCaseId != null) {
910-
final appealed = await dbService.lookupOrNull<ModerationCase>(
911-
dbService.emptyKey.append(ModerationCase, id: mc.appealedCaseId!));
910+
final appealed = await _db.lookupOrNull<ModerationCase>(
911+
_db.emptyKey.append(ModerationCase, id: mc.appealedCaseId!));
912912
if (appealed == null) {
913913
yield 'ModerationCase "${mc.caseId}" references an appealed case that does not exists.';
914914
}

app/lib/task/backend.dart

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1005,7 +1005,7 @@ class TaskBackend {
10051005
final status = await cache.taskPackageStatus(package).get(() async {
10061006
for (final rt in acceptedRuntimeVersions) {
10071007
final key = PackageState.createKey(_db, rt, package);
1008-
final state = await dbService.lookupOrNull<PackageState>(key);
1008+
final state = await _db.lookupOrNull<PackageState>(key);
10091009
// skip states where the entry was created, but no analysis has not finished yet
10101010
if (state == null || state.hasNeverFinished) {
10111011
continue;
@@ -1038,11 +1038,11 @@ class TaskBackend {
10381038
Future<void> Function(Payload payload) processPayload,
10391039
) async {
10401040
await backfillTrackingState();
1041-
await for (final state in dbService.query<PackageState>().run()) {
1041+
await for (final state in _db.query<PackageState>().run()) {
10421042
final zone = taskWorkerCloudCompute.zones.first;
10431043
// ignore: invalid_use_of_visible_for_testing_member
10441044
final payload = await updatePackageStateWithPendingVersions(
1045-
dbService,
1045+
_db,
10461046
state,
10471047
zone,
10481048
taskWorkerCloudCompute.generateInstanceName(),
@@ -1077,7 +1077,7 @@ class TaskBackend {
10771077
await cache.latestFinishedVersion(package).get(() async {
10781078
for (final rt in acceptedRuntimeVersions) {
10791079
final key = PackageState.createKey(_db, rt, package);
1080-
final state = await dbService.lookupOrNull<PackageState>(key);
1080+
final state = await _db.lookupOrNull<PackageState>(key);
10811081
// skip states where the entry was created, but no analysis has not finished yet
10821082
if (state == null || state.hasNeverFinished) {
10831083
continue;
@@ -1119,7 +1119,7 @@ class TaskBackend {
11191119
final semanticVersion = Version.parse(version);
11201120
for (final rt in acceptedRuntimeVersions) {
11211121
final key = PackageState.createKey(_db, rt, package);
1122-
final state = await dbService.lookupOrNull<PackageState>(key);
1122+
final state = await _db.lookupOrNull<PackageState>(key);
11231123
// Skip states where the entry was created, but the analysis has not finished yet.
11241124
if (state == null || state.hasNeverFinished) {
11251125
continue;

0 commit comments

Comments
 (0)