Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 19 additions & 10 deletions app/lib/account/consent_backend.dart
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,10 @@ abstract class ConsentKind {
/// Represents the backend for the consent handling and authentication.
class ConsentBackend {
final DatastoreDB _db;
final _actions = <String, ConsentAction>{
ConsentKind.packageUploader: _PackageUploaderAction(),
ConsentKind.publisherContact: _PublisherContactAction(),
ConsentKind.publisherMember: _PublisherMemberAction(),
late final _actions = <String, ConsentAction>{
ConsentKind.packageUploader: _PackageUploaderAction(_db),
ConsentKind.publisherContact: _PublisherContactAction(_db),
ConsentKind.publisherMember: _PublisherMemberAction(_db),
};

ConsentBackend(this._db);
Expand Down Expand Up @@ -316,6 +316,9 @@ abstract class ConsentAction {

/// Callbacks for package uploader consents.
class _PackageUploaderAction extends ConsentAction {
final DatastoreDB _db;
_PackageUploaderAction(this._db);

@override
Future<void> onAccept(Consent consent) async {
final packageName = consent.args![0];
Expand All @@ -335,7 +338,7 @@ class _PackageUploaderAction extends ConsentAction {
@override
Future<void> onReject(Consent consent, User? user) async {
final packageName = consent.args![0];
await withRetryTransaction(dbService, (tx) async {
await withRetryTransaction(_db, (tx) async {
tx.insert(await AuditLogRecord.uploaderInviteRejected(
fromAgent: consent.fromAgent,
package: packageName,
Expand All @@ -348,7 +351,7 @@ class _PackageUploaderAction extends ConsentAction {
@override
Future<void> onExpire(Consent consent) async {
final packageName = consent.args![0];
await withRetryTransaction(dbService, (tx) async {
await withRetryTransaction(_db, (tx) async {
tx.insert(await AuditLogRecord.uploaderInviteExpired(
fromAgent: consent.fromAgent,
package: packageName,
Expand Down Expand Up @@ -386,6 +389,9 @@ class _PackageUploaderAction extends ConsentAction {

/// Callbacks for requesting permission to use e-mail as publisher contact.
class _PublisherContactAction extends ConsentAction {
final DatastoreDB _db;
_PublisherContactAction(this._db);

@override
Future<void> onAccept(Consent consent) async {
final publisherId = consent.args![0];
Expand All @@ -400,7 +406,7 @@ class _PublisherContactAction extends ConsentAction {
@override
Future<void> onReject(Consent consent, User? user) async {
final publisherId = consent.args![0];
await withRetryTransaction(dbService, (tx) async {
await withRetryTransaction(_db, (tx) async {
tx.insert(await AuditLogRecord.publisherContactInviteRejected(
fromAgent: consent.fromAgent,
publisherId: publisherId,
Expand All @@ -414,7 +420,7 @@ class _PublisherContactAction extends ConsentAction {
@override
Future<void> onExpire(Consent consent) async {
final publisherId = consent.args![0];
await withRetryTransaction(dbService, (tx) async {
await withRetryTransaction(_db, (tx) async {
tx.insert(await AuditLogRecord.publisherContactInviteExpired(
fromAgent: consent.fromAgent,
publisherId: publisherId,
Expand Down Expand Up @@ -462,6 +468,9 @@ class _PublisherContactAction extends ConsentAction {

/// Callbacks for publisher member consents.
class _PublisherMemberAction extends ConsentAction {
final DatastoreDB _db;
_PublisherMemberAction(this._db);

@override
Future<void> onAccept(Consent consent) async {
final publisherId = consent.args![0];
Expand All @@ -479,7 +488,7 @@ class _PublisherMemberAction extends ConsentAction {
@override
Future<void> onReject(Consent consent, User? user) async {
final publisherId = consent.args![0];
await withRetryTransaction(dbService, (tx) async {
await withRetryTransaction(_db, (tx) async {
tx.insert(await AuditLogRecord.publisherMemberInviteRejected(
fromAgent: consent.fromAgent,
publisherId: publisherId,
Expand All @@ -492,7 +501,7 @@ class _PublisherMemberAction extends ConsentAction {
@override
Future<void> onExpire(Consent consent) async {
final publisherId = consent.args![0];
await withRetryTransaction(dbService, (tx) async {
await withRetryTransaction(_db, (tx) async {
tx.insert(await AuditLogRecord.publisherMemberInviteExpired(
fromAgent: consent.fromAgent,
publisherId: publisherId,
Expand Down
2 changes: 1 addition & 1 deletion app/lib/audit/backend.dart
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ class AuditBackend {
window = Duration(minutes: 2);
}

final query = dbService.query<AuditLogRecord>()
final query = _db.query<AuditLogRecord>()
..filter('created >', now.subtract(window));
final current = await query.run().toList();

Expand Down
4 changes: 3 additions & 1 deletion app/lib/package/backend.dart
Original file line number Diff line number Diff line change
Expand Up @@ -117,8 +117,10 @@ class PackageBackend {
}))!;
}

Stream<Package> allPackages() => db.query<Package>().run();

Stream<String> allPackageNames() {
return db.query<Package>().run().map((p) => p.name!);
return allPackages().map((p) => p.name!);
}

/// Retrieves the packages that need to be included in sitemap.txt.
Expand Down
2 changes: 1 addition & 1 deletion app/lib/search/backend.dart
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ class SearchBackend {
// initial scan of packages
final pool = Pool(concurrency);
final futures = <Future>[];
await for (final package in dbService.query<Package>().run()) {
await for (final package in packageBackend.allPackages()) {
if (package.isNotVisible) {
continue;
}
Expand Down
4 changes: 2 additions & 2 deletions app/lib/shared/integrity.dart
Original file line number Diff line number Diff line change
Expand Up @@ -907,8 +907,8 @@ class IntegrityChecker {
// TODO: verify fields once the other PR lands

if (mc.appealedCaseId != null) {
final appealed = await dbService.lookupOrNull<ModerationCase>(
dbService.emptyKey.append(ModerationCase, id: mc.appealedCaseId!));
final appealed = await _db.lookupOrNull<ModerationCase>(
_db.emptyKey.append(ModerationCase, id: mc.appealedCaseId!));
if (appealed == null) {
yield 'ModerationCase "${mc.caseId}" references an appealed case that does not exists.';
}
Expand Down
10 changes: 5 additions & 5 deletions app/lib/task/backend.dart
Original file line number Diff line number Diff line change
Expand Up @@ -1005,7 +1005,7 @@ class TaskBackend {
final status = await cache.taskPackageStatus(package).get(() async {
for (final rt in acceptedRuntimeVersions) {
final key = PackageState.createKey(_db, rt, package);
final state = await dbService.lookupOrNull<PackageState>(key);
final state = await _db.lookupOrNull<PackageState>(key);
// skip states where the entry was created, but no analysis has not finished yet
if (state == null || state.hasNeverFinished) {
continue;
Expand Down Expand Up @@ -1038,11 +1038,11 @@ class TaskBackend {
Future<void> Function(Payload payload) processPayload,
) async {
await backfillTrackingState();
await for (final state in dbService.query<PackageState>().run()) {
await for (final state in _db.query<PackageState>().run()) {
final zone = taskWorkerCloudCompute.zones.first;
// ignore: invalid_use_of_visible_for_testing_member
final payload = await updatePackageStateWithPendingVersions(
dbService,
_db,
state,
zone,
taskWorkerCloudCompute.generateInstanceName(),
Expand Down Expand Up @@ -1077,7 +1077,7 @@ class TaskBackend {
await cache.latestFinishedVersion(package).get(() async {
for (final rt in acceptedRuntimeVersions) {
final key = PackageState.createKey(_db, rt, package);
final state = await dbService.lookupOrNull<PackageState>(key);
final state = await _db.lookupOrNull<PackageState>(key);
// skip states where the entry was created, but no analysis has not finished yet
if (state == null || state.hasNeverFinished) {
continue;
Expand Down Expand Up @@ -1119,7 +1119,7 @@ class TaskBackend {
final semanticVersion = Version.parse(version);
for (final rt in acceptedRuntimeVersions) {
final key = PackageState.createKey(_db, rt, package);
final state = await dbService.lookupOrNull<PackageState>(key);
final state = await _db.lookupOrNull<PackageState>(key);
// Skip states where the entry was created, but the analysis has not finished yet.
if (state == null || state.hasNeverFinished) {
continue;
Expand Down