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
9 changes: 6 additions & 3 deletions app/lib/package/api_export/api_exporter.dart
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ ApiExporter? get apiExporter => ss.lookup(#_apiExporter) as ApiExporter?;
const _concurrency = 50;

class ApiExporter {
final DatastoreDB _db;

final ExportedApi _api;

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

ApiExporter({
ApiExporter(
this._db, {
required Bucket bucket,
}) : _api = ExportedApi(storageService, bucket);

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

Expand Down
6 changes: 4 additions & 2 deletions app/lib/service/services.dart
Original file line number Diff line number Diff line change
Expand Up @@ -245,8 +245,10 @@ Future<R> _withPubServices<R>(FutureOr<R> Function() fn) async {
registerAnnouncementBackend(AnnouncementBackend());
if (activeConfiguration.exportedApiBucketName != null) {
registerApiExporter(ApiExporter(
bucket: storageService
.bucket(activeConfiguration.exportedApiBucketName!)));
dbService,
bucket:
storageService.bucket(activeConfiguration.exportedApiBucketName!),
));
}
registerAsyncQueue(AsyncQueue());
registerAuditBackend(AuditBackend(dbService));
Expand Down
5 changes: 3 additions & 2 deletions app/test/package/api_export/api_exporter_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import 'package:googleapis/storage/v1.dart' show DetailedApiRequestError;
import 'package:logging/logging.dart';
import 'package:pub_dev/fake/backend/fake_auth_provider.dart';
import 'package:pub_dev/package/api_export/api_exporter.dart';
import 'package:pub_dev/shared/datastore.dart';
import 'package:pub_dev/shared/storage.dart';
import 'package:pub_dev/shared/utils.dart';
import 'package:pub_dev/shared/versions.dart';
Expand Down Expand Up @@ -46,7 +47,7 @@ void main() {
(fakeTime) async {
await storageService.createBucket('bucket');
final bucket = storageService.bucket('bucket');
final apiExporter = ApiExporter(bucket: bucket);
final apiExporter = ApiExporter(dbService, bucket: bucket);

await _testExportedApiSynchronization(
fakeTime,
Expand All @@ -61,7 +62,7 @@ void main() {
(fakeTime) async {
await storageService.createBucket('bucket');
final bucket = storageService.bucket('bucket');
final apiExporter = ApiExporter(bucket: bucket);
final apiExporter = ApiExporter(dbService, bucket: bucket);

await apiExporter.synchronizeExportedApi();

Expand Down
Loading