Skip to content

Commit 0346f4d

Browse files
authored
Explicit injected of dbService (#8267)
1 parent 72bb50e commit 0346f4d

File tree

3 files changed

+13
-7
lines changed

3 files changed

+13
-7
lines changed

app/lib/package/api_export/api_exporter.dart

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@ ApiExporter? get apiExporter => ss.lookup(#_apiExporter) as ApiExporter?;
3333
const _concurrency = 50;
3434

3535
class ApiExporter {
36+
final DatastoreDB _db;
37+
3638
final ExportedApi _api;
3739

3840
/// If [stop] has been called to stop background processes.
@@ -46,7 +48,8 @@ class ApiExporter {
4648
/// `null` when not started yet.
4749
Completer<void>? _stopped;
4850

49-
ApiExporter({
51+
ApiExporter(
52+
this._db, {
5053
required Bucket bucket,
5154
}) : _api = ExportedApi(storageService, bucket);
5255

@@ -136,7 +139,7 @@ class ApiExporter {
136139
/// This is intended to be scheduled from a daily background task.
137140
Future<void> synchronizeExportedApi({bool forceWrite = false}) async {
138141
final allPackageNames = <String>{};
139-
final packageQuery = dbService.query<Package>();
142+
final packageQuery = _db.query<Package>();
140143
var errCount = 0;
141144
await packageQuery.run().parallelForEach(_concurrency, (pkg) async {
142145
final name = pkg.name!;
@@ -251,7 +254,7 @@ class ApiExporter {
251254
var since = clock.ago(days: 3);
252255
while (claim.valid && !abort.isCompleted) {
253256
// Look at all packages changed in [since]
254-
final q = dbService.query<Package>()
257+
final q = _db.query<Package>()
255258
..filter('updated >', since)
256259
..order('-updated');
257260

app/lib/service/services.dart

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -245,8 +245,10 @@ Future<R> _withPubServices<R>(FutureOr<R> Function() fn) async {
245245
registerAnnouncementBackend(AnnouncementBackend());
246246
if (activeConfiguration.exportedApiBucketName != null) {
247247
registerApiExporter(ApiExporter(
248-
bucket: storageService
249-
.bucket(activeConfiguration.exportedApiBucketName!)));
248+
dbService,
249+
bucket:
250+
storageService.bucket(activeConfiguration.exportedApiBucketName!),
251+
));
250252
}
251253
registerAsyncQueue(AsyncQueue());
252254
registerAuditBackend(AuditBackend(dbService));

app/test/package/api_export/api_exporter_test.dart

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import 'package:googleapis/storage/v1.dart' show DetailedApiRequestError;
1212
import 'package:logging/logging.dart';
1313
import 'package:pub_dev/fake/backend/fake_auth_provider.dart';
1414
import 'package:pub_dev/package/api_export/api_exporter.dart';
15+
import 'package:pub_dev/shared/datastore.dart';
1516
import 'package:pub_dev/shared/storage.dart';
1617
import 'package:pub_dev/shared/utils.dart';
1718
import 'package:pub_dev/shared/versions.dart';
@@ -46,7 +47,7 @@ void main() {
4647
(fakeTime) async {
4748
await storageService.createBucket('bucket');
4849
final bucket = storageService.bucket('bucket');
49-
final apiExporter = ApiExporter(bucket: bucket);
50+
final apiExporter = ApiExporter(dbService, bucket: bucket);
5051

5152
await _testExportedApiSynchronization(
5253
fakeTime,
@@ -61,7 +62,7 @@ void main() {
6162
(fakeTime) async {
6263
await storageService.createBucket('bucket');
6364
final bucket = storageService.bucket('bucket');
64-
final apiExporter = ApiExporter(bucket: bucket);
65+
final apiExporter = ApiExporter(dbService, bucket: bucket);
6566

6667
await apiExporter.synchronizeExportedApi();
6768

0 commit comments

Comments
 (0)