Skip to content

Commit

Permalink
Synchronization logic for exported API (dart-lang#8203)
Browse files Browse the repository at this point in the history
* Draft of what a full sync could look like

* Updated ApiExported and added tests

* More logging

* stray file warning gone from tests

* Fix tests

* Fix logger name in exported_api.dart

* Remove skip from test

* Avoid caching security advisories
  • Loading branch information
jonasfj authored Nov 7, 2024
1 parent 51a366c commit 1cff64b
Show file tree
Hide file tree
Showing 8 changed files with 669 additions and 277 deletions.
378 changes: 201 additions & 177 deletions app/lib/package/api_export/api_exporter.dart

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion app/lib/package/api_export/exported_api.dart
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import '../../shared/storage.dart';
import '../../shared/versions.dart'
show runtimeVersion, runtimeVersionPattern, shouldGCVersion;

final _log = Logger('api_export:exported_bucket');
final _log = Logger('api_export.exported_api');

/// Minimum age before an item can be consider garbage.
///
Expand Down
3 changes: 1 addition & 2 deletions app/lib/package/backend.dart
Original file line number Diff line number Diff line change
Expand Up @@ -1255,8 +1255,7 @@ class PackageBackend {
emailBackend.trySendOutgoingEmail(outgoingEmail),
taskBackend.trackPackage(newVersion.package, updateDependents: true),
if (apiExporter != null)
apiExporter!
.updatePackageVersion(newVersion.package, newVersion.version!),
apiExporter!.synchronizePackage(newVersion.package),
]);
await tarballStorage.updateContentDispositionOnPublicBucket(
newVersion.package, newVersion.version!);
Expand Down
2 changes: 1 addition & 1 deletion app/lib/service/entrypoint/analyzer.dart
Original file line number Diff line number Diff line change
Expand Up @@ -85,5 +85,5 @@ Future _apiExporterMain(EntryMessage message) async {
message.protocolSendPort.send(ReadyMessage());
await popularityStorage.start();
await downloadCountsBackend.start();
await apiExporter!.uploadInForeverLoop();
await apiExporter!.start();
}
24 changes: 18 additions & 6 deletions app/lib/service/security_advisories/backend.dart
Original file line number Diff line number Diff line change
Expand Up @@ -39,22 +39,34 @@ class SecurityAdvisoryBackend {
}

Future<List<SecurityAdvisoryData>> lookupSecurityAdvisories(
String package,
) async {
return (await cache.securityAdvisories(package).get(() async {
String package, {
bool skipCache = false,
}) async {
final loadAdvisories = () async {
final query = _db.query<SecurityAdvisory>()
..filter('affectedPackages =', package);
return query
.run()
.map((SecurityAdvisory adv) => SecurityAdvisoryData.fromModel(adv))
.toList();
}))!;
};
if (skipCache) {
return await loadAdvisories();
}

return (await cache.securityAdvisories(package).get(loadAdvisories))!;
}

/// Create a [ListAdvisoriesResponse] for [package] using advisories from
/// cache.
Future<ListAdvisoriesResponse> listAdvisoriesResponse(String package) async {
final advisories = await lookupSecurityAdvisories(package);
Future<ListAdvisoriesResponse> listAdvisoriesResponse(
String package, {
bool skipCache = false,
}) async {
final advisories = await lookupSecurityAdvisories(
package,
skipCache: skipCache,
);
return ListAdvisoriesResponse(
advisories: advisories.map((a) => a.advisory).toList(),
advisoriesUpdated: advisories.map((a) => a.syncTime).maxOrNull,
Expand Down
11 changes: 2 additions & 9 deletions app/lib/tool/neat_task/pub_dev_tasks.dart
Original file line number Diff line number Diff line change
Expand Up @@ -119,9 +119,9 @@ void _setupGenericPeriodicTasks() {

// Exports the package name completion data to a bucket.
_daily(
name: 'export-package-name-completion-data-to-bucket',
name: 'synchronize-exported-api',
isRuntimeVersioned: true,
task: () async => await apiExporter?.uploadPkgNameCompletionData(),
task: () async => await apiExporter?.synchronizeExportedApi(),
);

// Deletes moderated packages, versions, publishers and users.
Expand Down Expand Up @@ -167,13 +167,6 @@ void _setupGenericPeriodicTasks() {
task: taskBackend.garbageCollect,
);

// Deletes exported API data for old runtime versions
_weekly(
name: 'garbage-collect-api-exports',
isRuntimeVersioned: true,
task: () async => apiExporter?.deleteObsoleteRuntimeContent(),
);

// Delete very old instances that have been abandoned
_daily(
name: 'garbage-collect-old-instances',
Expand Down
Loading

0 comments on commit 1cff64b

Please sign in to comment.